Question

In my application, I allow my users to either upload a picture from their photo library or take a picture. Once that picture is taken (or choosen) I use that AssetURL to do the following:

- (void)uploadImageWithAssetURL:(NSURL *)url named:(id)name withParameters:(NSDictionary *)parameters atPath:(NSString *)path
{
    ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
    [library assetForURL:url resultBlock:^(ALAsset *asset )
    {
        ALAssetRepresentation *rep = [asset defaultRepresentation];
        Byte *buffer = (Byte*)malloc(rep.size);
        NSUInteger buffered = [rep getBytes:buffer fromOffset:0.0 length:rep.size error:nil];
        NSData *data = [NSData dataWithBytesNoCopy:buffer length:buffered freeWhenDone:YES];

        NSString *extension = @".jpg";
        NSString *mimeType = @"image/jpeg";
        NSNumber *identifier = [parameters objectForKey:FileManagerOwnerObjectIDKey];
        NSString *filename = [NSString stringWithFormat:@"%@_%@%@", name, [_dateFormatter stringFromDate:[NSDate date]], extension];
        NSMutableURLRequest *request = [_httpClient multipartFormRequestWithMethod:@"POST" path:path parameters:parameters constructingBodyWithBlock: ^(id <AFMultipartFormData>formData) {
            [formData appendPartWithFileData:data name:@"file" fileName:filename mimeType:mimeType];
        }];

        AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];

        [operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject)
         {
             [_delegate fileManagerDidSuccessfullyUploadPicture:[NSDictionary dictionaryWithObjectsAndKeys:identifier, FileManagerOwnerObjectIDKey, name, FileManagerOwnerObjectTypeKey, section, FileManagerOwnerObjectSectionKey, nil]];

         } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
             [_delegate fileManagerDidNotSuccessfullyUploadPicture:[NSDictionary dictionaryWithObjectsAndKeys:identifier, FileManagerOwnerObjectIDKey, name, FileManagerOwnerObjectTypeKey, section, FileManagerOwnerObjectSectionKey, nil]];
         }];
        [operation start];
    }
    failureBlock:^(NSError *error )
    {
         NSLog(@"Error loading asset");
    }];
}

For some reason, if the picture is landscape, it will appear fine later on. However, if that picture's good orientation is portrait, it looks like it sends it as landscape to my Django Server and my server treats it as Landscape when resizing and so on. Therefore, all my portrait picture are upside down...

Any ideas?!

Was it helpful?

Solution

I know I answered this on Twitter, but for the benefit of anybody else having the issue:

A lot of photos (including those taken with iPhones) have rotation EXIF data embedded in them which some applications respect and some ignore.

By default, ImageKit won't do anything special with EXIF data. However, if you use the Transpose processor, it will read the EXIF metadata and apply the rotation it specifies.

More explanation is available here.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top