2016-11-23 81 views
1

我使用AFMultipartFormData正在上傳圖片和其他媒體上載正常。但後端結構要求我爲每個上傳的文件發送一個字符串值。在不使用編碼的情況下在AFMultipartFormData中發送NSString

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那裏。怎麼做?

回答

3

你可以通過附加參數與如下文件:

NSURLRequest *request = [manager.requestSerializer multipartFormRequestWithMethod:@"POST" URLString:@{@"FileDesc": mystring} parameters:nil constructingBodyWithBlock:^(id<AFMultipartFormData> formData) { 

       [formData appendPartWithFormData:eachImage name:@"myImage"]; 



      } error:&error]; 
相關問題