File Storage: downloading files, redirects and large files

Edited

This article explains how GET /file-storage/files/{id}/download returns a file, what happens with larger files, and what to do with Google Docs, Sheets and Slides.

How a download is returned

  • Files up to 2 MB are returned directly in the response body.

  • Files larger than 2 MB are returned as a 302 redirect to a temporary download link. Your HTTP client follows the redirect to get the file. The link expires after 60 seconds, so follow it straight away rather than storing it.

If your client sends the Authorization header on redirects

Some HTTP clients copy the Authorization header onto the redirected request, and the storage behind the temporary link rejects it. To avoid this, send x-apideck-follow-redirects: false. Instead of a redirect, you then get a 200 response with the link and its expiry:

{ "url": "https://…", "expires_at": "…" }

Fetch the url yourself, without the Authorization header.

Large files and timeouts

There's no fixed file size limit, but every download has to finish within a time limit of about 30 seconds. Within that time Apideck fetches the file from the provider before handing it to you. How large a file you can download therefore depends on how fast the provider delivers it. Very large files, or a slow provider, can hit the limit and return a 504.

If downloads of large files time out:

  • Retry, in case the provider was temporarily slow.

  • For Google Docs, Sheets and Slides, use export instead (see below). Exports don't pass through Apideck, so they aren't affected by the time limit.

  • Contact Apideck support through the Customer Portal (the Requests link at the top of this help center), your Slack channel with us, or support@apideck.com with the connector, file size and consumer ID, so we can look at your case.

Google Docs, Sheets and Slides: use export

Files created in Google Docs, Sheets or Slides aren't regular files, so they can't be downloaded as-is. Export them to a format such as PDF or Excel instead:

GET /file-storage/files/{id}/export?format=xlsx
  • You can tell these files apart by their mime_type, which starts with application/vnd.google-apps. (for example application/vnd.google-apps.spreadsheet).

  • format is required. The formats available for a file are listed in its export_formats field.

  • The response redirects you to Google, which delivers the exported file directly.

Uploaded Office files (for example an .xlsx you uploaded to Drive) are regular files. Use the normal download endpoint for those.

Related

Was this article helpful?

Sorry about that! Care to tell us more?

Thanks for the feedback!

There was an issue submitting your feedback
Please check your connection and try again.