gpt4 book ai didi

ios - 从 imagePickerController AFNetWorking 3.0 将图像上传到服务器

转载 作者:行者123 更新时间:2023-11-29 00:08:54 25 4
gpt4 key购买 nike

如何使用 AFNetworkingimagePickerController 将图像上传到服务器?我试过这个:

    NSMutableURLRequest *request = [self.requestSerializer multipartFormRequestWithMethod:@"POST" URLString:urlString parameters:params constructingBodyWithBlock:^(id <AFMultipartFormData> formData) {
[formData appendPartWithFileData:photo.data name:@"photo" fileName:@"photo.jpg" mimeType:@"image/jpeg"];
}];

但是我必须从哪里获取名称和文件名?

如果有人可以帮助我。

谢谢。

最佳答案

检查 AFURLRequestSerialization.h 文件以阅读您正在使用的方法的文档:

/**
Appends the HTTP header `Content-Disposition: file; filename=#{filename}; name=#{name}"` and `Content-Type: #{mimeType}`, followed by the encoded file data and the multipart form boundary.

@param data The data to be encoded and appended to the form data.
@param name The name to be associated with the specified data. This parameter must not be `nil`.
@param fileName The filename to be associated with the specified data. This parameter must not be `nil`.
@param mimeType The MIME type of the specified data. (For example, the MIME type for a JPEG image is image/jpeg.) For a list of valid MIME types, see http://www.iana.org/assignments/media-types/. This parameter must not be `nil`.
*/

只需将文件名设置为您希望在后端接收的任何文件名即可。如果不需要特殊的文件名,只需给它类似 @"photo.jpg"

关于ios - 从 imagePickerController AFNetWorking 3.0 将图像上传到服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47178172/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com