AFNetworking post image in nested json

前端 未结 1 1407
盖世英雄少女心
盖世英雄少女心 2020-12-18 12:50

I have to send a nested json request which includes an image in an inner hierarchy. eg:

{\"product\" : {
  \"catalogue_id\" : \"x\", 
   \"name\" : \"my prod         


        
相关标签:
1条回答
  • 2020-12-18 13:22

    Found the answer with some tinkering: product[image] in the name did the trick

    Sample code:

    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"];
                                      }];
    
    0 讨论(0)
提交回复
热议问题