C.Islas C.Islas - 6 months ago 33
iOS Question

Issue with uploading a JPEG, Google Drive saves it as a PNG

I'm having an issue with uploading a photo to Google Drive via the SDK made available for Objective-C.

The summary of the situation is the following, I create a folder with a defined name, after the folder is created I upload a finite number of photos stores in my app. I wait until I receive confirmation that a photo was uploaded successfully before trying the next one on the list.

The issue I'm having is the following, I know the photo file is ~9MB, and it hits Google Drive successfully. The problem is that I'm uploading it with a MIME type image/jpeg, the file that actually appears in Google Drive is a PNG image file, and it's 22 MB in size!!!!!!! I can't understand why it's interpreting it as a PNG, and why does the size grow so much.

This is my relevant code:

- (void) uploadPhotoToFolder:(NSString *)identifier withIndex:(int)index{
UIImage *content = [[photoArray objectAtIndex:index] objectAtIndex:0];
NSString *mimeType = @"image/jpeg";
GTLDriveFile *metadata = [GTLDriveFile object];
NSString *name =@"FileName";
metadata.name = name;

metadata.parents = @[identifier];

NSData *data = UIImagePNGRepresentation(content);
GTLUploadParameters *uploadParameters = [GTLUploadParameters uploadParametersWithData:data
MIMEType:mimeType];
GTLQueryDrive *query = [GTLQueryDrive queryForFilesCreateWithObject:metadata
uploadParameters:uploadParameters];
[self.service executeQuery:query completionHandler:^(GTLServiceTicket *ticket,
GTLDriveFile *updatedFile,
NSError *error) {
if (error == nil) {
//Notify that upload was successful
}
else {
//Notify that upload failed.
}

}];
}


Thank you in advance for any help.

Answer

You're using NSData *data = UIImagePNGRepresentation(content); which makes your image a PNG despite the MIME type you send.