Sending files from Google Drive straight to Amazon S3

Hey everyone, I’m working on a project where users can upload files to Amazon S3. Right now, they can do this from their computer without the files going through my server first. I’m using a jQuery file upload plugin for this.

I want to add an option for users to pick files from their Google Drive too. I’ve set up the Google Picker API, and I can get the file metadata when a user selects something. But I’m stuck on how to get these Google Drive files directly to S3.

Is there a way to do this without downloading the file to the user’s device first or sending it through my server? I really want to keep the direct-to-S3 upload process.

Here’s a simplified version of my current upload form:

<form action="s3-bucket-url" method="POST" enctype="multipart/form-data">
  <input type="hidden" name="key" value="file-name">
  <input type="hidden" name="AWSAccessKeyId" value="my-aws-key">
  <input type="hidden" name="acl" value="private">
  <input type="hidden" name="policy" value="base64-policy">
  <input type="hidden" name="signature" value="aws-signature">
  <input type="file" name="file" multiple>
</form>

Any ideas on how to make this work with Google Drive files? Thanks in advance for your help!

I’ve actually implemented something similar recently. Here’s what worked for me:

Instead of trying to send files directly from Drive to S3, I used the Google Drive API to get a downloadable link for the selected file. Then, I used that link to fetch the file content on the client side using JavaScript’s Fetch API.

Once I had the file content, I created a new File object and used that with my existing S3 upload logic. It’s not exactly a direct transfer, but it keeps the upload process on the client side without involving your server.

The tricky part was handling large files, as you might run into memory issues. I ended up implementing chunked uploads for files over a certain size.

It’s not a perfect solution, but it worked well for my use case. You might need to adjust based on your specific requirements and file types you’re dealing with.

I’ve tackled a similar challenge in one of my projects. Unfortunately, there’s no direct way to transfer files from Google Drive to S3 without involving your server or the user’s device. Google Drive doesn’t provide direct download URLs for security reasons.

One workaround I found effective was to use Google Drive’s API to download the file to your server temporarily, then upload it to S3. This maintains the user experience of selecting from Drive, but requires some server-side processing.

Alternatively, you could use Google Drive’s exportLinks to get a downloadable URL for certain file types, then pass this to your client-side code to download and immediately upload to S3. This keeps the transfer client-side but may not work for all file types.

Both approaches have trade-offs in terms of performance and complexity. The best choice depends on your specific requirements and constraints.

hey ethant, have u considered using google drive’s api to get a download url for the file? then u could pass that url to ur jquery plugin to upload directly to s3. might need some tweaks to ur current setup, but could work. just a thought!