【发布时间】:2016-07-13 11:58:24
【问题描述】:
我正在尝试使用 AFNetworking 3.0 将图像上传到我的服务器。我的服务器返回“请选择要上传的文件。”。这是我如何在我的 php 文件 $filename = $_FILES["file"]["name"]; 中捕获上传的文件。
-(void)uplodeImages :(NSString *)image {
NSMutableURLRequest *request = [[AFHTTPRequestSerializer serializer] multipartFormRequestWithMethod:@"POST" URLString:@"http://local/upload.php" parameters:nil constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
[formData appendPartWithFileURL:[NSURL fileURLWithPath:image] name:@"file" fileName:@"imagename.jpg" mimeType:@"image/jpeg" error:nil];
} error:nil];
AFURLSessionManager *manager = [[AFURLSessionManager alloc] initWithSessionConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]];
NSURLSessionUploadTask *uploadTask;
uploadTask = [manager uploadTaskWithStreamedRequest:request progress:^(NSProgress * _Nonnull uploadProgress) {
dispatch_async(dispatch_get_main_queue(), ^{
NSLog(@"Laddar...");
});
} completionHandler:^(NSURLResponse * _Nonnull response, id _Nullable responseObject, NSError * _Nullable error) {
if (error) {
NSLog(@"Error: %@", error);
} else {
NSLog(@"%@ %@", response, responseObject);
}
}];
[uploadTask resume];
}
【问题讨论】:
标签: ios afnetworking