是否可以通过Android API随机访问Google Drive文件? [英] Is it possible to have random access writes to a Google Drive file from the Android API?

查看:192
本文介绍了是否可以通过Android API随机访问Google Drive文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正尝试使用Android API在Google云端硬盘中录制音频并创建wav文件。我有一个第一遍,我写的文件长度为0字节的标题,因为我不知道录制的音频会有多长时间,我不想将它全部保存在内存中。一旦记录完成,我回到字节4并写入文件的长度。

这在使用RandomAccessFile时效果很好,但我无法弄清楚如何使用Google Drive API进行操作。 https://developers.google.com/drive/android/files



DriveContents类( https://developers.google.com/android/reference/com/google/android/gms/drive/DriveContents )不会以任何方式暗示内容。任何想法?

解决方案

我认为这样做不会有可能。 Google驱动器Apis( V2 V3 GDAA )都接受文件流(即串行流)作为内容。您可能知道您构建了元数据+内容并上传(创建,修补,更新)。

因为您需要修改您的文件头完成写入文件后,唯一的方法是完成本地文件中的所有内容,然后将其传送到GooDrive Api。在这种情况下,更新/补丁不会帮助你,因为你的头文件是GooDrive Apis已知的一大块字节的一部分,如 contents 。



逻辑上,V2和V3是直接REST API,因此它们以串行方式发送字节。 GDAA有一天可能会这样做(请参阅'云端硬盘文件的生命周期' ),但我不会屏住呼吸。

好运

I'm trying to record audio and create a wav file in Google Drive with the Android API. I have a first pass where I write the header with a file length of 0 bytes because I don't know how long the recorded audio will be and I don't want to keep it all in memory. Once the record is finished I seek back to byte 4 and write the length of the file.

This works great when using a RandomAccessFile but I can't figure out how to do something using the Google Drive API. https://developers.google.com/drive/android/files

The DriveContents class (https://developers.google.com/android/reference/com/google/android/gms/drive/DriveContents) doesn't hint at any way to seek within the contents. Any ideas?

解决方案

I don't think it will be possible this way. Google drive Apis (V2, V3, GDAA) all accept file streams (i.e. serial streams) as contents. You are probably aware that you construct metadata + contents and upload (create, patch, update).

Since you need to modify your file's header after you're finished writing to the file, the only way to do it is to finish everything in a local file and then hand it's stream to the GooDrive Api. The update/patch will not help you in this case since your header is a part of a chunk of bytes known to GooDrive Apis as contents.

It is logical, V2 and V3 are straight REST apis, so they send the bytes up in a serial fashion. There is some hope GDAA may do it one day (see 'Lifecycle of a Drive file'), but I wouldn't hold my breath.

Good Luck

这篇关于是否可以通过Android API随机访问Google Drive文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆