【发布时间】:2014-05-09 13:23:04
【问题描述】:
如何使用AFNetworking发布图片。我正在使用下面的代码发布图片。但是图片没有上传到服务器。发布图片后,我在结果“http://thisisswitch.com:8084/SmartSwitchService/UserImages/69684177-4601-4665-8890-5424e3fbff73.png”中获得了这个链接。
谁能告诉我代码有什么问题?
这是我的代码:
AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL:[NSURL URLWithString:BaseUrl]];
NSMutableURLRequest *request = [httpClient multipartFormRequestWithMethod:@"POST" path:posturl parameters:nil constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
[formData appendPartWithFormData:imgData name:@"image"];
}];
[httpClient registerHTTPOperationClass:[AFHTTPRequestOperation class]];
AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
NSDictionary *dict = (NSDictionary *)JSON;
} failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON) {
}];
[operation start];
【问题讨论】:
-
您确定问题不在您的 php 中吗?如果文件不是在服务器上创建的,则不应返回链接...您使用的是什么后端?自己写的?
-
我对这一行有疑问 [formData appendPartWithFormData:imgData name:@"image"];这一行的名字是什么
-
来自后端的.net
-
您使用的是 AFNetworking 1 还是 2?
标签: ios post afnetworking image-uploading