上传JPEG时出现问题,Google Drive将其保存为PNG



通过Objective-C提供的SDK将照片上传到Google Drive时遇到问题。

情况总结如下,我创建了一个具有定义名称的文件夹,创建文件夹后,我在应用程序中上传了有限数量的照片存储。我会等到收到照片上传成功的确认后再尝试列表上的下一张。

我遇到的问题是,我知道照片文件大约是9MB,它成功地进入了谷歌硬盘。问题是,我上传的是MIME类型的图像/jpeg,实际出现在Google Drive中的文件是PNG图像文件,大小为22MB!!!!!!!我不明白为什么它把它解释为PNG,为什么它的大小增长了这么多。

这是我的相关代码:

- (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.
}
}];
}

提前感谢您的帮助。

您使用的是NSData *data = UIImagePNGRepresentation(content);,它使您的图像成为PNG,而不考虑您发送的MIME类型。

最新更新