Unable to upload photo on smugmug iOS

saylisayli Registered Users Posts: 2 Beginner grinner
Hi,
I am trying to upload images on smugmug but getting the following error.

{
"stat": "fail",
"method": "smugmug.images.upload",
"code": 60,
"message": "Corrupt File. Please retry."
}

This is my piece of code:

if(imageData != nil){

[indicator startAnimating];

request = [NSMutableURLRequest new];
request.timeoutInterval =60.0;
[request setURL:[NSURL URLWithString:URL]];
[request setHTTPMethod:@POST];
//[request setCachePolicy:NSURLCacheStorageNotAllowed];

NSString *boundary = @"
14737809831466499882746641449";
NSString *contentType = [NSString stringWithFormat:@multipart/form-data; boundary=%@",boundary];
[request setValue:contentType forHTTPHeaderField: @Content-Type];

//[request setValue:@multipart/form-data forHTTPHeaderField: @ENCTYPE];

[request setValue:imageHash forHTTPHeaderField:@Content-MD5];
[request setValue:SmugalbumId forHTTPHeaderField:@X-Smug-AlbumID];
[request setValue:@1.2.0 forHTTPHeaderField:@X-Smug-Version];
//[request setValue:@no_image forHTTPHeaderField:@X-Smug-FileName];
[request setValue:sessionId forHTTPHeaderField:@X-Smug-SessionID];
[request setValue:@JSON forHTTPHeaderField:@X-Smug-ResponseType];

[request setValue:@true forHTTPHeaderField:@X-Smug-Pretty];

NSMutableData *body = [NSMutableData data];

[body appendData:NSString stringWithFormat:@"\r\n--%@\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding;
[body appendData:NSString stringWithFormat:@"Content-Disposition: form-data; name=\"%@\"; filename=\"%@\"\r\n", @"test", @"image51.png"] dataUsingEncoding:NSUTF8StringEncoding;
[body appendData:[@Content-Type: application/octet-stream\r\n\r\n dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[NSData dataWithData:imageData]];

NSLog(@%@",imageData);
// [body appendData:[NSData dataWithData:imageData]];

[body appendData:NSString stringWithFormat:@"\r\n--%@--\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding;
[request setHTTPBody:body];

[request addValue:[NSString stringWithFormat:@%lu, (unsigned long)[body length]] forHTTPHeaderField:@Content-Length];

return TRUE;

}else{

response.text = NO_IMAGE;

return FALSE;
}

Please tell me where am i going wrong?
Sign In or Register to comment.