Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9000097
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:16:03+00:00 2026-06-16T00:16:03+00:00

I am trying to upload camera images from iPhone to my web server but

  • 0

I am trying to upload camera images from iPhone to my web server but some how the images change it’s orientation when i download them from server.This only happens with camera images and not simple images uploaded to device from my machine.Plz help me.

i have use this condition to rotate image on server side:

//obj will be Orientation passed while uploading image on server its value will be either 1 or 3or 6 or 8

switch ((ushort)obj)
               {
                   case 1: //up
                       return 0;
                   case 3: //down
                       return 180;
                   case 6: //left
                       return 90;
                   case 8: //right
                       return 270;
                   default:
                       return 0;
               }

But still i am getting the same problem

Here is my code for Upload image:

-(void)uploadSingleFile
{
    if(!self.objWebServices.bSyncWasOn)
    {
        NSLog(@"STOP upload Single File RETURN");
        [self Call_SaveSyncedImageID];
        return;
    }
    SyncItem* item = [arrSelSyncItemIDS objectAtIndex:nSyncItemIndex];

    if(item.nType == SYNC_STATUS_NOT_SELECTED || item.nType == SYNC_STATUS_SYNC_DONE)
    {
        nSyncItemIndex = nSyncItemIndex + 1;
        if([arrSelSyncItemIDS count] > nSyncItemIndex)
        {
            NSLog(@"Called uploadSingleFile");
            [self uploadSingleFile];
            return;
        }
        else
        {
            //[self LoadImages:!bShowHideSyncImages];
            [SVProgressHUD dismiss];
            [BtnStopSync setTitle:@"Start sync" forState:UIControlStateNormal];
            self.objWebServices.bSyncWasOn = NO;
            self.objWebServices.isFileUpload = NO;

            if( [[NSUserDefaults standardUserDefaults] boolForKey:@"Notification_State"] ) // Setting Switch Bool
            {
                UIAlertView *Alert = [[UIAlertView alloc] initWithTitle:@"winkflash" message:@"*** Sync completed successfully." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
                [Alert show];
            }
        }
    }
    NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
    NSString *srtprefSessionId = [NSString stringWithFormat:@"%@",[prefs objectForKey:@"prefSessionId"]];

    BOOL isTrash = FALSE;   
    NSString *StrPath = @"/Pictures/";      //Change 
    ALAsset* temp = item.itemAsset;
    NSDate* assetDate = (NSDate*)[temp valueForProperty:@"ALAssetPropertyDate"];

    NSString* strID = @"";
    strID = [[temp valueForProperty:@"ALAssetPropertyURLs"] description];
    strID = [strID stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];

    NSString* strImageType = @"";
    if ([strID rangeOfString:@"jpg"].location != NSNotFound || [strID rangeOfString:@"JPG"].location != NSNotFound ){
        strImageType = @"jpg";
    }
    else if ([strID rangeOfString:@"png"].location != NSNotFound || [strID rangeOfString:@"PNG"].location != NSNotFound )
        strImageType = @"png";


    NSDateFormatter* df = [[NSDateFormatter alloc]init];
    [df setDateFormat:@"MM/dd/yyyy"];
    NSString *result = [df stringFromDate:assetDate];

    NSTimeInterval timeInterval = [assetDate timeIntervalSince1970];
    ALAssetRepresentation *rep = [temp defaultRepresentation];

    //------------------ metadata -------------------------------------------------------
    NSDictionary *imageMetadata = [rep metadata];
    NSString *strOrt=[NSString stringWithFormat:@"%@",[imageMetadata valueForKey:@"Orientation"]];
    NSString *strOrientation;

    if([strOrt isEqualToString:@"6"])
    {
        strOrientation=@"1";
    }
    if([strOrt isEqualToString:@"8"])
    {
        strOrientation=@"3";
    }
    if([strOrt isEqualToString:@"3"])
    {
        strOrientation=@"6";
    }
    if([strOrt isEqualToString:@"1"])
    {
        strOrientation=@"8";
    }
    NSLog(@"print strOrientation:%@",strOrientation);
    //-----------------------------------------------------------------------------------

    StrPath = [StrPath stringByAppendingFormat:@"%d.%@",(int)timeInterval,strImageType];
    UIImage *image = [UIImage imageWithCGImage:[rep fullResolutionImage]];
    NSData *dataObj = nil;
    dataObj = UIImagePNGRepresentation(image);
    NSString* StrFileData = [Base64 encode:dataObj];
    NSString* strFileHash = [dataObj md5Test];

    //----------------------------------------------------
    NSMutableDictionary *DictRequest = [[NSMutableDictionary alloc]init];
    [DictRequest setObject:srtprefSessionId forKey:@"SessionId"];
    [DictRequest setObject:StrPath forKey:@"Path"];
    [DictRequest setValue:[NSNumber numberWithBool:isTrash] forKey:@"UploadDirectlyToTrashbin"];
    [DictRequest setObject:StrFileData forKey:@"FileData"];
    [DictRequest setObject:strFileHash forKey:@"FileHash"];
    [DictRequest setObject:result forKey:@"DateCreated"];

    BOOL isNULL = [self stringIsEmpty:strOrientation];
    if(!isNULL)
    {
        [DictRequest setObject:strOrientation forKey:@"Orientation"];
    }


    NSString *jsonString = [DictRequest JSONRepresentation];
    NSString *strUrl=[NSString stringWithFormat:@"%@",FileUpload_URL];
    NSURL *url1=[NSURL URLWithString:strUrl];
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url1];
    [request setTimeoutInterval:60.0];
    [request setHTTPMethod:@"POST"];
    NSData *postData = [jsonString dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
    NSString *postLength = [NSString stringWithFormat:@"%d",[postData length]];
    [request setHTTPBody:postData];
    [request setValue:postLength forHTTPHeaderField:@"Content-Length"];
    [request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];


    if(theConnection)
        [self Set2Defaults];

    theConnection = [[NSURLConnection alloc]initWithRequest:request delegate:self];

    [SVProgressHUD dismiss];

    if(theConnection)
        webData = [NSMutableData data];
    else
        NSLog(@"Connection Failed !!!");
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T00:16:03+00:00Added an answer on June 16, 2026 at 12:16 am

    This is due to the way orientation is stored within UIImage.

    I use this function inside a category on UIImage.

    - (UIImage *)fixOrientation {
    
        // No-op if the orientation is already correct
        if (self.imageOrientation == UIImageOrientationUp) return self;
    
        // We need to calculate the proper transformation to make the image upright.
        // We do it in 2 steps: Rotate if Left/Right/Down, and then flip if Mirrored.
        CGAffineTransform transform = CGAffineTransformIdentity;
    
        switch (self.imageOrientation) {
            case UIImageOrientationDown:
            case UIImageOrientationDownMirrored:
                transform = CGAffineTransformTranslate(transform, self.size.width, self.size.height);
                transform = CGAffineTransformRotate(transform, M_PI);
                break;
    
            case UIImageOrientationLeft:
            case UIImageOrientationLeftMirrored:
                transform = CGAffineTransformTranslate(transform, self.size.width, 0);
                transform = CGAffineTransformRotate(transform, M_PI_2);
                break;
    
            case UIImageOrientationRight:
            case UIImageOrientationRightMirrored:
                transform = CGAffineTransformTranslate(transform, 0, self.size.height);
                transform = CGAffineTransformRotate(transform, -M_PI_2);
                break;
            case UIImageOrientationUp:
            case UIImageOrientationUpMirrored:
                break;
        }
    
        switch (self.imageOrientation) {
            case UIImageOrientationUpMirrored:
            case UIImageOrientationDownMirrored:
                transform = CGAffineTransformTranslate(transform, self.size.width, 0);
                transform = CGAffineTransformScale(transform, -1, 1);
                break;
    
            case UIImageOrientationLeftMirrored:
            case UIImageOrientationRightMirrored:
                transform = CGAffineTransformTranslate(transform, self.size.height, 0);
                transform = CGAffineTransformScale(transform, -1, 1);
                break;
            case UIImageOrientationUp:
            case UIImageOrientationDown:
            case UIImageOrientationLeft:
            case UIImageOrientationRight:
                break;
        }
    
        // Now we draw the underlying CGImage into a new context, applying the transform
        // calculated above.
        CGContextRef ctx = CGBitmapContextCreate(NULL, self.size.width, self.size.height,
                                                 CGImageGetBitsPerComponent(self.CGImage), 0,
                                                 CGImageGetColorSpace(self.CGImage),
                                                 CGImageGetBitmapInfo(self.CGImage));
        CGContextConcatCTM(ctx, transform);
        switch (self.imageOrientation) {
            case UIImageOrientationLeft:
            case UIImageOrientationLeftMirrored:
            case UIImageOrientationRight:
            case UIImageOrientationRightMirrored:
                // Grr...
                CGContextDrawImage(ctx, CGRectMake(0,0,self.size.height,self.size.width), self.CGImage);
                break;
    
            default:
                CGContextDrawImage(ctx, CGRectMake(0,0,self.size.width,self.size.height), self.CGImage);
                break;
        }
    
        // And now we just create a new UIImage from the drawing context
        CGImageRef cgimg = CGBitmapContextCreateImage(ctx);
        UIImage *img = [UIImage imageWithCGImage:cgimg];
        CGContextRelease(ctx);
        CGImageRelease(cgimg);
        return img;
    }
    

    Just run this when getting the image from the imagePicker.

    Then when you upload and download it will keep the orientation.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im trying to upload some images using the Flickr.net API.The Images are uploaded but
I´m trying to upload a file which is fetched from a server. But when
I'm trying to upload an image on a remote server. If i download images
I'm trying to upload images to a php file, everything works, but sometimes when
I'm trying to upload a file .txt in my web space, but then the
I am trying to upload a file but the browser spinner rolls forever, server
I'm trying to upload a jpeg image buffer I got back from the Camera.
I'm trying to upload an image from android to a PHP server by using
I am trying to upload an image to server using using XMLHttpRequest but fails.
I am trying to upload a file to the server directory from client machine.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.