从 imagePickerController AFNetWorking 3.0 上传图片到服务器

Upload image to server from imagePickerController AFNetWorking 3.0

如何使用 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"