Skip to main content

Client Uploads

Amongst all the other great features of Tigris, free egress fees is another example of what makes us stand out from other providers. We care about the bandwidth costs and we want to make it as cheap as possible for you to use Tigris. That's why we've made it so that you can upload files directly to Tigris from the client side.

We leverage the presigned URLs features to allow you to upload files directly to Tigris from the client side.

Client side uploads are a great way to upload objects to a bucket directly from the browser as it allows you to upload objects to a bucket without having to proxy the objects through your server saving costs on bandwidth.

Uploading an object

You can use the upload method from client package to upload objects directly to Tigris from the client side.

import { upload } from "@tigrisdata/storage/client";

upload accepts the following parameters:

  • path: (Required) A string specifying the path to the object
  • body: (Required) A blob object as File or Blob
  • options: (Optional) A JSON object with the following optional parameters:

options

ParameterRequiredValues
urlNoThe URL to upload the file to.
accessNoThe access level for the object. Possible values are public and private.
onUploadProgressNoCallback to track upload progress: onUploadProgress({loaded: number, total: number, percentage: number}).
configNoA configuration object to override the default configuration.

Example

<input type="file" onchange="handleFileChange(event)" />

<script>
function handleFileChange(event) {
const file = event.target.files[0];
upload("file.txt", file, {
url: "/api/upload",
access: "private",
onUploadProgress: ({ loaded, total, percentage }) => {
console.log(`Uploaded ${loaded} of ${total} bytes (${percentage}%)`);
},
});
}
</script>

You can see a full example here.