将带有MP3文件的ID3标签上传到Google云端硬盘 - iOS SDK

时间:2014-04-15 09:59:50

标签: ios google-drive-api

我目前可以使用iOS SDK将MP3文件上传到Google云端硬盘,但是我遇到了一个问题,我无法在文件中组合ID3标签。有没有办法将这些信息直接添加到GTLDriveFile中,或者至少有一些替代方法?

当前代码:

GTLDriveParentReference *parentRef = [GTLDriveParentReference object];
parentRef.identifier = self.kDriveMusicDirID;
parentRef.isRoot = NO;

GTLDriveFileThumbnail *thumbnail = [[GTLDriveFileThumbnail alloc] init];
thumbnail.image = GTLEncodeWebSafeBase64(UIImageJPEGRepresentation(file.image, 80));
thumbnail.mimeType = @"image/jpeg";

GTLDriveFile *driveFile = [[GTLDriveFile alloc] init];
NSString *title = [NSString stringWithFormat:@"%@ - %@.mp3", file.artist,    file.songTitle];
driveFile.title = title;
driveFile.mimeType = @"audio/mp3";
driveFile.parents = @[parentRef];
driveFile.thumbnail = thumbnail;

AVURLAsset *songAsset = [AVURLAsset assetWithURL:file.assetURL];
[self extractDataForAsset:songAsset withCallback:^(NSData *data, NSError *error)
{
if (error == nil)
{
GTLUploadParameters *uploadParameters =
[GTLUploadParameters uploadParametersWithData:data
                                     MIMEType:driveFile.mimeType];

GTLQueryDrive *query = [GTLQueryDrive queryForFilesInsertWithObject:driveFile
                                                   uploadParameters:uploadParameters];

[self.driveService executeQuery:query
              completionHandler:^(GTLServiceTicket *ticket, id object, NSError *error)
   {
   if (error == nil)
   {
     completion(nil);
   }
   else
   {
     completion(error);
   }
 }];
}
else
{
  //handle the error. notification that the upload has failed.
}
}];

1 个答案:

答案 0 :(得分:1)

Google云端硬盘允许我们以简单上传,分段上传和可恢复上传方式上传文件。如果您要将元数据与要上传的数据一起发送,则可以制作一个多部分/相关请求

要使用分段上传,请对方法的/上传URI发出POST或PUT请求,并添加查询参数uploadType=multipart

例如:

POST https://www.googleapis.com/upload/drive/v2/files?uploadType=multipart

有关详细信息,请参阅HERE