I want to send a document that I obtained as NSData with DocuSign API to a web that has a service to do it.
The service is
POST /api/v1/rest/groups/[:idgroup]/documents/upload/[:oauthtoken]
and the required parameters are:
file --> The file to upload (Type: inputstream)
fileName --> The name of the new file to upload (Type: string)
length --> The size of the file to upload in bytes (Type: long)
I'm trying to do the request with this example Uploading Image via POST in Objective C but I have a service error that says "InvalidParametersServiceApiException"
My code is:
NSString *filename = #"docusignTest.pdf";
NSMutableURLRequest* request= [[NSMutableURLRequest alloc] init];
[request setURL:[NSURL URLWithString:urlString]];
[request setHTTPMethod:#"POST"];
NSString *boundary = #"---------------------------14737809831466499882746641449";
NSString *contentType = [NSString stringWithFormat:#"multipart/form-data; boundary=%#",boundary];
[request addValue:contentType forHTTPHeaderField: #"Content-Type"];
NSMutableData *postbody = [NSMutableData data];
[postbody appendData:[[NSString stringWithFormat:#"\r\n--%#\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[postbody appendData:[[NSString stringWithFormat:#"Content-Disposition: form-data; name=\"fileName\"; \r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
[postbody appendData:[[NSString stringWithFormat:#"\r\n%#",filename] dataUsingEncoding:NSUTF8StringEncoding]];
[postbody appendData:[[NSString stringWithFormat:#"\r\n--%#\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[postbody appendData:[[NSString stringWithFormat:#"Content-Disposition: form-data; name=\"length\"; \r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
[postbody appendData:[[NSString stringWithFormat:#"\r\n%lu",(unsigned long)oResponseData.length] dataUsingEncoding:NSUTF8StringEncoding]];
[postbody appendData:[[NSString stringWithFormat:#"\r\n--%#\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[postbody appendData:[#"Content-Type: application/octet-stream\r\n\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
[postbody appendData:[NSData dataWithData:oResponseData]];
[postbody appendData:[[NSString stringWithFormat:#"\r\n--%#--\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[request setHTTPBody:postbody];
NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
NSString *responseString = [[NSString alloc] initWithData:returnData encoding:NSUTF8StringEncoding];
Here's a suggestion: Instead of ignoring the response and the error, ask sendSynchronousRequest to supply them both to you, then examine what you are getting. It's rather mad to send a POST request without any error handling. The data you sent might be wrong, and servers are notorious about wanting you to get it right, but good servers will tell you what is wrong. The server may have problems. The URL may be wrong. The device may not have a connection.
And posting exactly what you received, without any interpretation by you, might help. Reading the documentation for the service you are calling might also help. No two services are the same.
The example of this link is very helpul.
NSString *filename = #"docusignTest.pdf";
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:urlString]];
[request setHTTPMethod:#"POST"];
NSString *boundary = #"---------------------------14737809831466499882746641449";
NSString *contentType = [NSString stringWithFormat:#"multipart/form-data; boundary=%#", boundary];
[request addValue:contentType forHTTPHeaderField:#"Content-Type"];
NSMutableData *body = [NSMutableData data];
[body appendData:[[NSString stringWithFormat:#"\r\n--%#\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithFormat:#"Content-Disposition: form-data; name=\"file\"; filename=\"%#\"\r\n", filename] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[#"Content-Type: application/octet-stream\r\n\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[NSData dataWithData:oResponseData]];
[body appendData:[[NSString stringWithFormat:#"\r\n--%#\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithFormat:#"Content-Disposition: form-data; name=\"fileName\"\r\n\r\n%#", filename] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithFormat:#"\r\n--%#\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithFormat:#"Content-Disposition: form-data; name=\"length\"\r\n\r\n%d", oResponseData.length] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithFormat:#"\r\n--%#\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[request setHTTPBody:body];
NSURLResponse *response;
NSError *error2;
NSData *oResponseData2 = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error2];
NSMutableString *jsonResponse2 = [[NSMutableString alloc] initWithData:oResponseData2 encoding:NSUTF8StringEncoding];
Related
I managed to send some string with image data to the server. However array which contains the images has more than 1 object. I can perfectly get the first image from server but rest seems to disappear. Is there any way to send multiple data files to server or is there anything wrong in my for loop to send the images ? Server side code seems to work fine since it gets the strings and the first image file so I think there must be something wrong in the objective-c part of my code.
NSString *urlString = #"http://www.somesite.com/cgi-bin/somefile.py";
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
[request setURL:[NSURL URLWithString:urlString]];
[request setHTTPMethod:#"POST"];
NSString *boundary = #"---------------------------14737809831466499882746641449";
NSString *contentType = [NSString stringWithFormat:#"multipart/form-data; boundary=%#",boundary];
[request addValue:contentType forHTTPHeaderField: #"Content-Type"];
NSMutableData *body = [NSMutableData data];
NSString *filenames = [NSString stringWithFormat:#"some string"]; //set name here
[body appendData:[[NSString stringWithFormat:#"\r\n--%#\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithFormat:#"Content-Disposition: form-data; name=\"sessionString\"\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[filenames dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithFormat:#"\r\n--%#\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithFormat:#"Content-Disposition: form-data; name=\"userEmail\"\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[sharedSingletonCenter.emailString dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithFormat:#"\r\n--%#\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];
for (int i = 0; i < [self.pagesArray count]; i++) {
NSData* imageData = UIImagePNGRepresentation(self.pagesArray[i]);
NSLog(#"added %i", i+1);
[body appendData:[[NSString stringWithFormat:#"Content-Disposition: form-data; name=\"file_%i\"; filename=\".png\"\r\n", i + 1] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[#"Content-Type: application/octet-stream\r\n\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[NSData dataWithData:imageData]];
[body appendData:[[NSString stringWithFormat:#"\r\n--%#--\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];
}
// setting the body of the post to the reqeust
[request setHTTPBody:body];
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];
NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
NSString *returnString = [[NSString alloc] initWithData:returnData encoding:NSUTF8StringEncoding];
NSLog(#"%#", returnString);
NSLog(#"finish");
The problem is that multipart form elements are separated with
[NSString stringWithFormat:#"\r\n--%#\r\n",boundary]
But then terminated with
[NSString stringWithFormat:#"\r\n--%#--\r\n",boundary]
But you're inserting that termination boundary string at the end of each file. You want to change your code to do that only at the end. Thus:
NSMutableData *body = [NSMutableData data];
NSString *filenames = [NSString stringWithFormat:#"some string"]; //set name here
[body appendData:[[NSString stringWithFormat:#"\r\n--%#\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithFormat:#"Content-Disposition: form-data; name=\"sessionString\"\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[filenames dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithFormat:#"\r\n--%#\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithFormat:#"Content-Disposition: form-data; name=\"userEmail\"\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[sharedSingletonCenter.emailString dataUsingEncoding:NSUTF8StringEncoding]];
for (int i = 0; i < [self.pagesArray count]; i++) {
[body appendData:[[NSString stringWithFormat:#"\r\n--%#\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];
NSData* imageData = UIImagePNGRepresentation(self.pagesArray[i]);
NSLog(#"added %i", i+1);
[body appendData:[[NSString stringWithFormat:#"Content-Disposition: form-data; name=\"file_%i\"; filename=\".png\"\r\n", i + 1] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[#"Content-Type: application/octet-stream\r\n\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[NSData dataWithData:imageData]];
}
[body appendData:[[NSString stringWithFormat:#"\r\n--%#--\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];
// setting the body of the post to the reqeust
[request setHTTPBody:body];
I've been trying to get this code working to send a torrent's data to the µTorrent Web API, unfortunately, as far as I can tell, nobody has ever tried to make a .torrent file handler for µTorrent in Objective-C before, which isn't all that surprising.
I have this code here at the moment, but I invariably get the error message: "Error: torrent file content not supplied in form parameter".
NSMutableURLRequest * request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:[NSString stringWithFormat:#"%#?token=%#&action=add-file", [self getBaseURL], token]]];
NSString * boundary = #"!#!#!#!#!#!#!#!#!";
NSMutableData * body = [NSMutableData alloc];
NSData * torrentFileContents = [[NSFileManager defaultManager] contentsAtPath:fileName];
[request setHTTPMethod:#"POST"];
[request setValue:[NSString stringWithFormat:#"multipart/form-data; boundary=%#", boundary] forHTTPHeaderField:#"Content-Type"];
[request setValue:[NSString stringWithFormat:#"multipart/form-data; boundary=%#", boundary] forHTTPHeaderField:#"enctype"];
[body appendData:[[NSString stringWithFormat:#"\r\n--%#\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithFormat:#"Content-Type: %#\r\n\r\n", #"application/x-bittorrent"] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithFormat:#"Content-Disposition: form-data; name=\"torrent_file\"; filename=\"%#\"\r\n", fileName] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithFormat:#"Content-Length: %ld\r\n", [torrentFileContents length]] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[NSData dataWithData:torrentFileContents]];
[body appendData:[[NSString stringWithFormat:#"\r\n--%#--\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[request setHTTPBody:body];
Why are you putting the content type and length in the request body? Did you try using setValue to add the necessary HTTP headers like Content-Type?
for example:
[request addValue:#"text/xml;charset=utf-8" forHTTPHeaderField:#"Content-Type"];
I found an example of what I wanted to do, written in JS, I was able to make it work by tweaking the code to look like this.
NSMutableURLRequest * request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:[NSString stringWithFormat:#"%#?token=%#&action=add-file", [self getBaseURL], token]]];
NSString * boundary = [NSString stringWithFormat:#"AJAX-----------------------%f", [[[NSDate alloc] init] timeIntervalSince1970]];
NSMutableData * body = [NSMutableData alloc];
NSData * torrentFileContents = [[NSFileManager defaultManager] contentsAtPath:fileName];
[request setHTTPMethod:#"POST"];
[request addValue:[NSString stringWithFormat:#"multipart/form-data; boundary=%#", boundary] forHTTPHeaderField:#"Content-Type"];
[body appendData:[[NSString stringWithFormat:#"--%#\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithFormat:#"Content-Disposition: form-data; name=\"torrent_file\"; filename=\"%#\"\r\n", fileName] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithFormat:#"Content-Type: %#\r\n\r\n", #"application/x-bittorrent"] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[NSData dataWithData:torrentFileContents]];
[body appendData:[[NSString stringWithFormat:#"\r\n--%#--\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[request setHTTPBody:body];
return request;
I am attempting to write a method/function in objective c to post data to an online php script. All is going well, Its successfully uploads as many files as I provide it with but I cannot figure out to send variables along with these files. I've spent hours now looking through this site and I am unable to find an example that posts files as well as variables.
NSURL * postURL = [NSURL URLWithString:serverURL];
NSString * contentBoundary = #"-14737809831466499882746641449";
NSString * contentType = [NSString stringWithFormat:#"multipart/form-data; boundary=%#", contentBoundary];
// Build Request
NSMutableURLRequest * urlRequest = [NSMutableURLRequest requestWithURL:postURL];
[urlRequest setHTTPMethod:#"POST"];
[urlRequest addValue:contentType forHTTPHeaderField: #"Content-Type"];
NSMutableData * postBody = [NSMutableData data];
NSMutableString * postString = [NSMutableString stringWithFormat:#""];
for(NSString * key in dataArray) [postString appendString:[NSString stringWithFormat:#"%#=%#&", key, [dataArray objectForKey:key]]];
[postString deleteCharactersInRange:NSMakeRange([postString length] -1, 1)]; // Trim trailing ampersand from string
NSData * postData = [postString dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:NO];
[postBody appendData:[NSData dataWithData:postData]];
if(attachments != nil){
for(NSString * filePath in attachments){
NSString * fileName = [filePath lastPathComponent];
NSData * attachedFile = [NSData dataWithContentsOfFile:filePath];
[postBody appendData:[[NSString stringWithFormat:#"\r\n--%#\r\n", contentBoundary] dataUsingEncoding:NSUTF8StringEncoding]];
[postBody appendData:[[NSString stringWithFormat:#"Content-Disposition:form-data;name=\"userfile[]\"; filename=\"%#\"\r\n", fileName] dataUsingEncoding:NSUTF8StringEncoding]];
[postBody appendData:[[NSString stringWithFormat:#"Content-Type:application/octet-stream\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
[postBody appendData:[NSData dataWithData:attachedFile]];
[postBody appendData:[[NSString stringWithFormat:#"\r\n--%#--\r\n", contentBoundary] dataUsingEncoding:NSUTF8StringEncoding]];
}
}
NSString * postLength = [NSString stringWithFormat:#"%d", [postBody length]];
[urlRequest setValue:postLength forHTTPHeaderField:#"Content-Length"];
[urlRequest setHTTPBody:postBody];
Any help would be appreciated.
You can try appending the variable's values to the posted data in the following manner :
// text parameter
[postbody appendData:[[NSString stringWithFormat:#"--%#\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[postbody appendData:[[NSString stringWithFormat:#"Content-Disposition: form-data; name=\"applicationId\"\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
NSString *parameterValue1=[dict objectForKey:#"applicationId"];
[postbody appendData:[parameterValue1 dataUsingEncoding:NSUTF8StringEncoding]];
[postbody appendData:[#"\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
Hope that works for you. Above code is just an example of the parameter sent with the file upload.
I'm trying to do a simple file upload using objective c and NSUrlRequest.
My current (more or less googled and put together) code:
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
[request setURL:[NSURL URLWithString:#"http://127.0.0.1:8000/api/upload/"]];
[request setHTTPMethod:#"POST"];
NSString *boundary = [NSString stringWithString:#"---------------------------14737809831466499882746641449"];
NSString *contentType = [NSString stringWithFormat:#"multipart/form-data; boundary=%#",boundary];
[request addValue:contentType forHTTPHeaderField: #"Content-Type"];
NSMutableData *postData = [NSMutableData data];
[postData appendData:[[NSString stringWithFormat:#"\r\n--%#\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
// Append the Usertoken
[postData appendData:[[NSString stringWithString:#"Content-Disposition: form-data; name=\"token\"\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
[postData appendData:[[NSString stringWithString:#"Content-Type: application/json\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
[postData appendData:[[NSString stringWithFormat:#"%#", token] dataUsingEncoding:NSUTF8StringEncoding]];
// Append the file
[postData appendData:[[NSString stringWithFormat:#"\r\n--%#\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[postData appendData:[[NSString stringWithFormat:#"Content-Disposition: form-data; name=\"fileupload\"; filename=\"%#\"\r\n", file]dataUsingEncoding:NSUTF8StringEncoding]];
[postData appendData:[[NSString stringWithString:#"Content-Type: application/octet-stream\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
// Close
[postData appendData:[[NSString stringWithFormat:#"\r\n--%#--\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
// Append
[request setHTTPBody:postData];
All uploaded files having Zero Bytes filesize. The serverside part is working correctly. Tested with cURL.
Did i forget something?
Found my mistake. Was a very simple one, happened because of my lack of knowledge about http.
I forgot to append the file data after the octet-stream
NSData *photo = [[NSFileManager defaultManager] contentsAtPath:file];
// Append the file
[postData appendData:[[NSString stringWithFormat:#"\r\n--%#\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[postData appendData:[[NSString stringWithFormat:#"Content-Disposition: form-data; name=\"fileupload\"; filename=\"%#\"\r\n", file]dataUsingEncoding:NSUTF8StringEncoding]];
[postData appendData:[[NSString stringWithString:#"Content-Type: application/octet-stream\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
[postData appendData:[NSData dataWithData:photo]];
I had a problem with the uploading an image into the server.Also I need to upload a string value to the server with that image. The Image uploading is fine but I am not succeeded so far to upload the string. The following is my code for the uploading. Please help me.Thanq.
NSData *imageData = UIImageJPEGRepresentation(theImage,0.9);
NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease];
[request setURL:[NSURL URLWithString:urlString]];
[request setHTTPMethod:#"POST"];
NSString* width =#"10";
[request setValue:#"300" forHTTPHeaderField:#"Keep-Alive"];
[request setValue:#"keep-live" forHTTPHeaderField:#"Connection"];
[request setValue:width forHTTPHeaderField:#"spotfk"];
NSString *boundary = [NSString stringWithString:#"---------------------------14737809831466499882746641449"];
NSString *contentType = [NSString stringWithFormat:#"multipart/form-data; boundary=%#",boundary];
[request addValue:contentType forHTTPHeaderField: #"Content-Type"];
NSMutableData *body = [NSMutableData data];
[body appendData:[[NSString stringWithFormat:#"\r\n--%#\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithString:#"Content-Disposition: form-data; name=\"userfile\"; filename=\"ipodfile.jpg\"\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithString:#"Content-Type: application/octet-stream\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[NSData dataWithData:imageData]];
[body appendData:[[NSString stringWithFormat:#"\r\n--%#--\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[request setHTTPBody:body];
Spots* spotObj=[spotsList objectAtIndex:spotIdValue-1];
SpotItems* spotItemObj=[[SpotItems alloc]init];
spotItemObj.imageX_Coordinate=0.0;
spotItemObj.imageY_Coordinate=0.0;
spotItemObj.imageWidth=spotObj.spotWidth;
spotItemObj.imageHight=spotObj.spotHight;
spotItemObj.imageName=#"logo.png";
UIView* subView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, spotObj.spotWidth, spotObj.spotHight)];
subView.backgroundColor=[UIColor clearColor];
spotItemObj.subView=subView;
UIImageView* newSpotItemImageView=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, spotObj.spotWidth, spotObj.spotHight)];
newSpotItemImageView.image=[UIImage imageNamed:spotItemObj.imageName];
[spotItemObj.subView addSubview:newSpotItemImageView];
[spotObj.spotsItemsList addObject:spotItemObj];
[spotItemObj release];
if([spotObj.spotsItemsList count]==2)
{
[self startInternalAnimation:spotObj.spotId-1];
}
NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
NSString *returnString = [[NSString alloc] initWithData:returnData encoding:NSUTF8StringEncoding];
I got the solution,
That is we need to make the code as follows. The proble is not using dataUsingEndcoding method and boundaries now the code is as follows.
NSMutableData *postBody = [NSMutableData data];
[postBody appendData:[[NSString stringWithFormat:#"--%#\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[postBody appendData:[[NSString stringWithString:#"Content-Disposition: form-data; name=\"spotfk\"\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
[postBody appendData:[[NSString stringWithString:spotFk] dataUsingEncoding:NSUTF8StringEncoding]];
[postBody appendData:[[NSString stringWithFormat:#"\r\n--%#\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[postBody appendData:[[NSString stringWithString:#"Content-Disposition: form-data; name=\"media\"; filename=\"test.png\"\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
[postBody appendData:[[NSString stringWithString:#"Content-Type: application/octet-stream\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
[postBody appendData:imageData];
[postBody appendData:[[NSString stringWithFormat:#"\r\n--%#--\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[request setHTTPBody:postBody];