i capture the image using image picker, at the that time image is in its actual position. but after uploading it on server it became horizontal. i don't get any clue why that happening.
here is my code
NSString *urlString = @"Url";
NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease];
[request setURL:[NSURL URLWithString:urlString]];
[request setHTTPMethod:@"POST"];
NSMutableData *body = [NSMutableData data];
NSString *boundary = [NSString stringWithString:@"---------------------------14737809831466499882746641449"];
NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@", boundary];
[request addValue:contentType forHTTPHeaderField:@"Content-Type"];
// file
NSData *imageData = UIImageJPEGRepresentation(image.image, 90);
[body appendData:[[NSString stringWithFormat:@"--%@\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
// [body appendData:[[NSString stringWithString:@"Content-Disposition: attachment; name=\"user_photo\"; filename=\"photoes.jpg\"\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"image\"; filename=\"%@.jpg\"\r\n",@"ImageNmae"] 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 stringWithString:@"\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithFormat:@"--%@\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"desc\"\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithString:ImageDesc.text] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithString:@"\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
// close form
[body appendData:[[NSString stringWithFormat:@"--%@--\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
// set request body
[request setHTTPBody:body];
//return and test
NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
NSString *returnString = [[NSString alloc] initWithData:returnData encoding:NSUTF8StringEncoding];
i find the solution here is code.
its being a nice query for the media uploading.
When you capture the Image from your device it fix the orientation for the particular Image. suppose you capture image in landscape mode & when you show this with your imageView it displays itself in portrait mode because basic Device configuration does both of Support for the Image (landscape & portrait) then it might pretend itself as portrait While actually stored in landscape. As result it saves over server in landscape While you displaying image in portrait in your UI (imageView). finally 1) image was written horizontally on device. 2) you have shown it vertically on UI due to portrait mode active for Application. 3) But When it will be written on server it takes its original mode(horizontal).
So as per best suggestion you should display the Media in proper mode in Application.
The orientation (rotation in your case) is in the exif data of your image. You need to pre-rotate the images on the iOS or post-rotate them on your server.
On iOS you can check the
imageOrientation
property ofUIImage
.You can get the transform with that code snipped (you need to set a size or change the code part. Size could be the original size):
Of course your need that to apply the transform somehow to your UIImage. But i think you will find that in other questions on stackoverflow. Maybe start here.
Isn't the 90 a rotation angle ?
Edit after reading docs
Looks like 90 should be 0.9. Might not be the problem though.