我使用上传正常的AFMultipartFormData
在服务器上上传图片和其他媒体。但是后端结构要求我为我上传的每个文件发送一个字符串值。
for(NSData *eachImage in dataStringArray) {
NSString *mystring = [dataTypeArray objectAtIndex:[dataStringArray indexOfObject:eachImage]];
NSLog(@"%@, %@",mystring,[mystring dataUsingEncoding:NSASCIIStringEncoding]);
NSURLRequest *request = [manager.requestSerializer multipartFormRequestWithMethod:@"POST" URLString:string parameters:nil constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
[formData appendPartWithFormData:eachImage name:@"myImage"];
[formData appendPartWithFormData:[mystring dataUsingEncoding:NSASCIIStringEncoding]
name:@"FileDesc"];
} error:&error];
现在假设myString
为@"0"
,因此NSASCIIStringEncoding
会将其转换为<30>
,但我只想要0
。怎么做?
答案 0 :(得分:3)
您可以使用文件传递其他参数,如下所示:
NSURLRequest *request = [manager.requestSerializer multipartFormRequestWithMethod:@"POST" URLString:@{@"FileDesc": mystring} parameters:nil constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
[formData appendPartWithFormData:eachImage name:@"myImage"];
} error:&error];