1
votes

This question concerns adding a new row to a CSV file that exists in Google Drive using the Google Drive REST API.

On my Android device, I have a CSV file that I am building locally. If I add a row to the local CSV, I want to also add that row to the CSV that resides on Google Drive.

I've got the fileId of the CSV, and I can PUT the file to do a direct replacement, but I'm trying to save bandwidth as the file size grows.

I have been looking into JSON Patch as the transport to perform this, but I cannot find a concrete example after looking for days. For instance, how does JSON Patch write to the CSV file? Is the "path:" parameter the column header? Is a "op", "add" needed for each column?

I just need to pointed in the right direction.

2

2 Answers

1
votes

To my best knowledge, it is not possible. You are trying to append (modify) the content of a file and the only way I know of in both the REST Api and the GDAA is to get the content, modify it and upload. It is possible that GDAA may (one day) internally do some diff / incremental optimization, but I doubt it.

My rational for this guess is that the content is being shipped as base64-ed, gzip-ed, ... binary stream with no embedded knowledge of the mime type, so the 'append' functionality would get quite complex.

The PATCH functionality you'r looking into deals only with METADATA (title, mime, modi-dates, parentIDs, etc...). See the fields available in Try it! on the bottom of this page.

Good Luck

1
votes

In case anyone else comes across this question, an alternative solution (which doesn't involve switching to using a Google Sheets file) would be to move the read-modify-write API calls to a small service hosted on Google Apps Script and call that service from your application using the recently-announced Execution API.

You would call the hosted script with the new row to be appended to the file, and the script (running in the cloud and with very fast access to the Drive API) would get the file content, append the new row, and then save the file back to Drive. This would save bandwidth between your mobile application and the hosted script.