How to upload file to box from ios app? -
i got following box developers site.
curl https://upload.box.com/api/2.0/files/content \ -h "authorization: bearer access_token" \ -f filename=@file_name \ -f parent_id=parent_folder_id
- f indicates ? how make request url ?
-f: emulate filled-in form in user has pressed submit button. causes curl post data using content-type multipart/form-data according rfc 2388 standard. -f accepts parameters -f "name=contents" contents read file, use <@filename> contents. when specifying file, can specify file content type appending ';type=' file name.
emulate fill-in form -f. let's fill in 3 fields in form. 1 field file name post, 1 field name , 1 field file description. want post file have written named "cooltext.txt".
curl example (sending couple fields , file):
curl -f "file=@cooltext.txt" -f "yourname=daniel" \ -f "filedescription=cool text file cool text inside" \ http://www.post.com/postit.cgi
objective-c example (sending 1 form value):
/* * create mutable url request , method post content type form */ nsmutableurlrequest *request = [nsmutableurlrequest requestwithurl:[nsurl urlwithstring:@"http://www.exmaple.com/post"]]; [request sethttpmethod:@"post"]; [request setvalue:@"application/x-www-form-urlencoded" forhttpheaderfield:@"content-type"]; /* * build http body */ nsdata *data = [@"firstname" datausingencoding:nsutf8stringencoding]; [request sethttpbody:data]; [request setvalue:[nsstring stringwithformat:@"%u", data.length] forhttpheaderfield:@"content-length"]; /* * make request , return result */ nserror *error; nshttpurlresponse *response; nsdata *result = [nsurlconnection sendsynchronousrequest:request returningresponse:&response error:&error]; if (error) { nslog(@"request error: %@", error); return; } nsstring *formattedresult = [[nsstring alloc] initwithdata:result encoding:nsutf8stringencoding]; nslog(@"result: %@ http headers: %@", formattedresult, response.allheaderfields);
references:
curl man pages
rfc 2388 standard
Comments
Post a Comment