Upload And Convert Google Drive Spreadhseet

Okay, I just needed to stick with this a bit longer to get it figured out. The key is to use a two-part resumable upload rather than messing around trying to get the multipart form data formatted correctly for upload in a single request. Doing the upload in two parts made it fairly simple to use HTTP node to get this done.

For future readers, my workflow looks something like this

  1. Get the file to update. In my case this is from the IMAP email node which triggers the next HTTP request node, but it could be any node that provides some binary data to upload
  2. Send the initial request with the file metadata to the Google Drive API with an HTTP Request node
    • Details on the format of the request can be found here in the API documentation for a resumable upload and also in either the create or update endpoint documentation, depending on the type of operation you are doing
    • You will want to make sure the request body is JSON content containing the file metadata. The important part for this metadata is to set the mimeType to application/vnd.google-apps.spreadsheet, which indicates the uploaded file should be converted to a Google Sheet
    • Set a X-Upload-Content-Type header with the original mime type of the file you are uploading. Make sure this mime type matches one of the types supported for conversion in the about API endpoint
    • It is also necessary to set the Full Response option to true to get the response headers
  3. Use a merge node to merge the result of the initial HTTP request with the first node that contains the binary data of the file
  4. Use a second HTTP Request node to upload the file content
    • Details on the format for this request can be found in the API documentation for a resumable upload
    • The URL for the request should be retrieved using an expression for the Location response header from the first HTTP request
    • The request body should contain the binary data of the file

Hopefully this helps someone in the future, took me a while to figure out!

2 Likes