我打算使用asiformdatarequest.my代码将图像上传到服务器,例如:
UIImage *image = [UIImage imageNamed:@"testicon.jpg"];
NSData *imgData = [[NSData alloc] initWithData:UIImageJPEGRepresentation((image), 0.5)];
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:ADDRESS,myType,action]];
ASIFormDataRequest *currentRequest = [ASIFormDataRequest requestWithURL:url];
[currentRequest setPostFormat:ASIMultipartFormDataPostFormat];
[currentRequest addRequestHeader:@"Content-Type" value:@"multipart/form-data"];
[currentRequest setRequestMethod:@"POST"];
[currentRequest setPostValue:@"1" forKey:@"user_id"];
NSLog(@"responseString = %@",responseString);
但是服务器未返回正确的结果。这可能是什么问题?
最佳答案
您没有设置数据-
[currentRequest setData:imgData forKey:@"file"];
关于ios - 如何使用asiformdatarequest上传图像,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/10545200/