【发布时间】:2014-12-09 14:00:40
【问题描述】:
我已遵循 Drive API 指南 (https://developer.android.com/google/play-services/drive.html),我的应用现在可以顺利上传照片,但我现在尝试上传视频 (mp4),但没有成功。
有谁知道如何做到这一点?该视频是一个新生成的 mp4 文件,我知道它在设备上的存储路径。
图片是这样处理的:
Drive.DriveApi.newDriveContents(mDriveClient).setResultCallback(
new ResultCallback<DriveContentsResult>() {
@Override
public void onResult(DriveContentsResult result) {
if (!result.getStatus().isSuccess()) {
Log.i(TAG, "Failed to create new contents.");
return;
}
OutputStream outputStream = result.getDriveContents().getOutputStream();
// Write the bitmap data from it.
ByteArrayOutputStream bitmapStream = new ByteArrayOutputStream();
image.compress(Bitmap.CompressFormat.JPEG, 80, bitmapStream);
try {
outputStream.write(bitmapStream.toByteArray());
} catch (IOException e1) {
Log.i(TAG, "Unable to write file contents.");
}
image.recycle();
outputStream = null;
String title = Shared.getOutputMediaFile(Shared.MEDIA_TYPE_IMAGE).getName();
MetadataChangeSet metadataChangeSet = new MetadataChangeSet.Builder()
.setMimeType("image/jpeg").setTitle(title)
.build();
Log.i(TAG, "Creating new pic on Drive (" + title + ")");
Drive.DriveApi.getFolder(mDriveClient,
mPicFolderDriveId).createFile(mDriveClient,
metadataChangeSet, result.getDriveContents());
}
});
}
我感兴趣的是文件的替代品,在这种情况下指向“video/mp4”。
【问题讨论】:
-
如何将 csv 文件上传到 gdrive,就像您对图像/视频所做的那样
-
如果您上传像 2 GB 这样的大视频,此代码将崩溃...您在 ByteArrayOutputStream 中写入整个文件...不好
标签: android google-drive-android-api