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,
    },
})

This gives back a token valid for some amount of time. 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
}
circle-exclamation

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

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