objective c - AFNetworking upload file to server, parameters -



objective c - AFNetworking upload file to server, parameters -

i trying upload file this:

nsmutabledictionary * lparameters = [nsmutabledictionary dictionary]; [lparameters setobject:@"temp.jpg" forkey:@"file"]; nsmutableurlrequest *request = [self multipartformrequestwithmethod:@"post" path:@"uploads/add.json" parameters:lparameters constructingbodywithblock: ^(id <afmultipartformdata>formdata) { nsdata * info = [nsdata datawithcontentsoffile:filepath]; [formdata appendpartwithfiledata:data name:@"temp.jpg" filename:@"temp.jpg" mimetype:@"image/jpeg"]; }]; afjsonrequestoperation *operation = [afjsonrequestoperation jsonrequestoperationwithrequest:request success:^(nsurlrequest *request, nshttpurlresponse *response, id json){ ....

my upload json looking this:

http://base/url/uploads/add.json

and have 1 parameter "file". server returns me error: "mandatory parameter not specified: file". how should set parameter. why doesn't work:

nsmutabledictionary * lparameters = [nsmutabledictionary dictionary]; [lparameters setobject:@"temp.jpg" forkey:@"file"];

help please.

you shouldn't setting temp.jpg in parameters dictionary. instead, seek setting name in appendpartwithfiledata:... file.

if doesn't prepare it, please provide backtrace server corresponding error.

objective-c afnetworking

Comments

Popular posts from this blog

delphi - blogger via idHTTP : error 400 bad request -

c++ - compiler errors when initializing EXPECT_CALL with function which has program_options::variables_map as parameter -

How do I check if an insert was successful with MySQLdb in Python? -