AFNetworking post image in nested json

I need to send a json subquery that includes an image in an internal hierarchy. eg:

{"product" : {
  "catalogue_id" : "x", 
   "name" : "my product", 
   "image" : #<image>
  } 
}

The problem is that if I try to use multipartFormRequestWithMethod:path:parameters:constructingBodyWithBlock:(s appendPartWithFileData:name:fileName:mimeType:), passing in the catalogueid and name as params, the image field is added after "product", for example:

{"product" : {
  "catalogue_id" : "x", 
   "name" : "my product"
  } ,
   "image" : #<image>
}

Is it possible to indicate that the image field is nested at a certain depth?

Thanks heaps

+3
source share
1 answer

Found an answer with some masters: product[image]in the title did a trick

Code example:

NSMutableURLRequest *request = [[client sharedInstance]
                         multipartFormRequestWithMethod:@"POST" 
                                                   path:@"/catalogues/1/products.json" 
                                             parameters:params
                              constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
                                  [formData appendPartWithFileData:img
                                                              name:@"product[image]" 
                                                          fileName:@"myimage.jpg" 
                                                          mimeType:@"image/jpg"];
                                  }];
+10
source

Source: https://habr.com/ru/post/1568574/


All Articles