Is It Possible To Have Random Access Writes To A Google Drive File From The Android Api?
Solution 1:
Try using FileChannel for random access.
You can get the FileChannel with FileOutputStream#getChannel, then seek using FileChannel#position(long). Writing to the OutputStream will then start from the set position.
Note: I would advise to flush the OutputStream before accessing the FileChannel.
Solution 2:
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.
Post a Comment for "Is It Possible To Have Random Access Writes To A Google Drive File From The Android Api?"