Error uploading photo on smug mug
sayli
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?
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?
0
Comments
That error message means that the file did not match the Content-MD5 header. I don't know how you are computing and formatting that header, since the variable imageHash seems to come from outside the chunk of code included in your post.
Sorcerer and API Guy at SmugMug