【问题标题】:Issue with uploading a JPEG, Google Drive saves it as a PNG上传 JPEG 时出现问题,Google 云端硬盘将其保存为 PNG
【发布时间】:2016-06-02 05:33:46
【问题描述】:

我在通过适用于 Objective-C 的 SDK 将照片上传到 Google Drive 时遇到问题。

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

我遇到的问题如下,我知道照片文件约为 9MB,并且成功访问了 Google Drive。问题是我上传的是 MIME 类型的图像/jpeg,实际出现在 Google Drive 中的文件是 PNG 图像文件,大小为 22 MB!!!!!!!!!!我不明白为什么它会将其解释为 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.
            }

        }];
}

提前感谢您的帮助。

【问题讨论】:

    标签: ios objective-c google-drive-api


    【解决方案1】:

    您使用的是NSData *data = UIImagePNGRepresentation(content);,尽管您发送的是 MIME 类型,但它会使您的图像成为 PNG。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-12-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多