ios - 上传图片到 Cloudinary IOS
<p><p>我无法通过 HTTPS POST 请求将图像上传到 Cloudinary 托管,我想使用简单的 API 方法而不是 SDK。我在将图像格式化为字节数组缓冲区或 Base64 编码时遇到问题。</p>
<p>这是我的代码:</p>
<pre><code>UIImage *image = ;
NSData *imageData = UIImagePNGRepresentation(image);
NSString *strImageData = ;
NSURL *url = ;
NSMutableURLRequest *request = ;
request.HTTPMethod = @"POST";
NSString *strRequest = ;
request.HTTPBody = ;
[[ dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
NSDictionary *recievedData = ;
NSLog(@"RECEIVED: %@", recievedData);
}] resume];
</code></pre>
<p>不幸的是,我从服务器收到以下答复:“不支持的源 URL...”</p>
<p>我确实尝试了很多其他方法,但我无法让它发挥作用。</p>
<p><strong>更新:</strong>当我将 URL 链接放在"file"参数中时,一切正常。</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>我对 Cloudinary API 没有任何经验,但我希望这会有所帮助。我查看了关于“<a href="http://cloudinary.com/documentation/upload_images#uploading_with_a_direct_call_to_the_api" rel="noreferrer noopener nofollow">Uploading with a direct call to the API</a>”的文档'。</p>
<p>我认为您需要提供 'file' 和 'upload_preset' 作为 POST 参数(不连接为正文中的数据)。</p>
<pre><code>UIImage *image = ;
NSData *imageData = UIImagePNGRepresentation(image);
NSString *strImageData = ;
NSURL *url = ;
NSMutableURLRequest *request = ;
request.HTTPMethod = @"POST";
// Replace this:
//NSString *strRequest = ;
//request.HTTPBody = ;
// With this:
NSString *imageDataStr = [ initWithData:imageData encoding:NSUTF8StringEncoding];
;
;
[[ dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
NSDictionary *recievedData = ;
NSLog(@"RECEIVED: %@", recievedData);
}] resume];
</code></pre></p>
<p style="font-size: 20px;">关于ios - 上传图片到 Cloudinary IOS,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/41812907/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/41812907/
</a>
</p>
页:
[1]