For the complete documentation index, see llms.txt. Markdown versions of documentation pages are available by appending .md to page URLs.
Skip to content

Writing your own uploader

If you're writing an app on top of Shade, this is how you upload files.

We've built the Shade uploader to be as easy as possible to integrate into your own app while maximizing upload speeds.

Multipart Uploads

We recommend always using multipart uploads. We have a single part API but from S3 limitations, it only supports files up to 5GB. Multipart uploads support files up to 5TB.

Steps

1. Make sure you have a valid ShadeFS token. All calls will require this.

const resp = await axios.get(`https://api.shade.inc/workspaces/drives/${driveId}/shade-fs-token`, {
    headers: {
        Authorization: apiKey,
    },
})

The account the API key belongs to needs edit access to the drive. This gives back a token that is currently valid for one hour. We recommend decoding it manually and reading the exp field to know when it expires:

const MUST_BE_LONGER_THAN_TO_BE_VALID = 240

const exp = jwtDecode(tokenJWT).exp
if (!exp) {
    throw new Error("No exp attribute in decoded jwt")
}

if (exp - Date.now() / 1000 < MUST_BE_LONGER_THAN_TO_BE_VALID) {
    // Token expires too soon, fetch another one
}

The token's aud claim is the drive ID. Its sub claim identifies the user in the form "Name" <user-id@shadeuser> and is not an email address.

2. Make sure that you've created the directories that you want to upload to. This call looks something like this:

Directories are created recursively, so if you pass /a/b/c/d.txt and only /a exists, it will create /b, /c.

3. Initiate the multipart upload to the destination path. This call looks something like this:

Decide on a part size! We've found 64-128mb work well for most end users

4. Now we can work on the parts. For each part, you will need to presign it first:

5. Now upload the part to the presigned URL. This call looks something like this:

6. Now just complete the upload

7. If the upload fails, abort it

If any step fails after you've initiated the upload, abort it so the partial upload is cleaned up:

Example

Putting it all together, you get something like this to control your upload.

You can make it faster by parallelizing this function and parallelizing the part uploads.

Last updated

Was this helpful?