ios - Server receives no data from NSURLSessionUploadTask -
i'm trying upload file via multipart request using nsurlsessionuploadtask via afnetworking. request executes , receives response server, server not receiving data in form.
ios code
nsstring *urlstring = [[nsurl urlwithstring:urlstring relativetourl:self.baseurl] absolutestring]; nserror *error = nil; nsmutableurlrequest *request = [self.requestserializer multipartformrequestwithmethod:@"post" urlstring:urlstring parameters:params constructingbodywithblock:^(id<afmultipartformdata> formdata) { // [formdata appendpartwithfiledata:[nsdata datawithcontentsofurl:[nsurl fileurlwithpath:path]] name:@"video" filename:[path lastpathcomponent] mimetype:@"video/mp4"]; } error:&error]; if ([account isauthenticated]) {; nsstring *authheader = [nsstring stringwithformat:@"bearer %@", account.accesstoken]; [request setallhttpheaderfields:@{@"authorization": authheader}]; } nsurlsessionuploadtask *task = [self uploadtaskwithstreamedrequest:request progress:progress completionhandler:^(nsurlresponse * __unused response, id responseobject, nserror *error) { if (error) { } else { } }]; [task resume];
here header info request afnetworkingactivitylogger:
post 'http://127.0.0.1:8000/upload/': { "accept-language" = "en;q=1, fr;q=0.9, de;q=0.8, zh-hans;q=0.7, zh-hant;q=0.6, ja;q=0.5"; authorization = "bearer 270f985de7ebf0aa49b7ff1cad8377e007141f94"; "content-length" = 225974; "content-type" = "multipart/form-data; boundary=boundary+4597b504492e1006"; "user-agent" = "test/1.0 (ipad simulator; ios 7.1; scale/1.00)"; } (null)
i'm using django on server side. here's test view:
class uploadview(view): def post(self, request, *args, **kwargs): logger.debug("files: {0} | data: {1}".format(request.files, request.post)) return httpresponse(content=json.dumps({"test": "2"}), content_type='application/json')
but both files , post objects empty:
files: <multivaluedict: {}> | data: <querydict: {}>
this works without multipart request- sending post request without file upload querydict populated. 1 thing i'm unsure fact body of request "(null)" according afnetworkingactivitylogger output.
any appreciated! i'm stumped.
from docs -[nsurlsession uploadtaskwithstreamedrequest:] (looks using):
... body stream , body data in request object ignored, , nsurlsession calls delegate’s urlsession:task:neednewbodystream: method provide body data.
have implemented delegate method?
Comments
Post a Comment