Skip to navigation

JavaScript and Node.js

Upload, download and share files from Node.js with the AWS SDK for JavaScript v3.

The AWS SDK for JavaScript v3 (@aws-sdk/client-s3) works with Zata. Point the client at the Zata endpoint, and you can use the normal S3 commands from Node.js.

Tested with @aws-sdk/client-s3 3.1095.0 on Zata in October 2026.

Before you start

  • A bucket. See Create a bucket.

  • An access key and secret key from the same region as the bucket. See Access keys.

  • Node.js with the SDK installed:

    npm install @aws-sdk/client-s3 @aws-sdk/s3-request-presigner

    You need @aws-sdk/s3-request-presigner only for download and upload links.

Connection settings

SettingValue
endpointhttps://idr01.zata.ai for Indore, https://bom01.zata.ai for Mumbai
regionus-east-1
credentialsaccess key and secret key from Access Keys in the Zata console. The key must be from the same region as the bucket.
forcePathStyletrue
requestChecksumCalculation / responseChecksumValidation"WHEN_REQUIRED"

Create the client

Keep your keys out of the code. Put them in the environment variables ZATA_ACCESS_KEY and ZATA_SECRET_KEY, then create the client. For a bucket in Mumbai, use https://bom01.zata.ai.

import { S3Client } from "@aws-sdk/client-s3";
const s3 = new S3Client({
endpoint: "https://idr01.zata.ai",
region: "us-east-1",
forcePathStyle: true,
requestChecksumCalculation: "WHEN_REQUIRED",
responseChecksumValidation: "WHEN_REQUIRED",
credentials: {
accessKeyId: process.env.ZATA_ACCESS_KEY,
secretAccessKey: process.env.ZATA_SECRET_KEY,
},
});

The two checksum settings are needed from SDK version 3.729 (January 2025): without them, large uploads fail with XAmzContentSHA256Mismatch.

The examples on this page use ES modules (import) and top-level await: save them in a .mjs file, or set "type": "module" in package.json.

Upload and list files

import { PutObjectCommand, ListObjectsV2Command } from "@aws-sdk/client-s3";
import { readFile } from "node:fs/promises";
await s3.send(new PutObjectCommand({
Bucket: "my-bucket",
Key: "folder/myfile.txt",
Body: await readFile("myfile.txt"),
}));
const { Contents = [] } = await s3.send(new ListObjectsV2Command({ Bucket: "my-bucket", Prefix: "folder/" }));
console.log(Contents.map((o) => o.Key));

Download a file

import { GetObjectCommand } from "@aws-sdk/client-s3";
import { writeFile } from "node:fs/promises";
const res = await s3.send(new GetObjectCommand({ Bucket: "my-bucket", Key: "folder/myfile.txt" }));
await writeFile("myfile-copy.txt", await res.Body.transformToByteArray());

List your buckets

import { ListBucketsCommand } from "@aws-sdk/client-s3";
const { Buckets = [] } = await s3.send(new ListBucketsCommand({}));
console.log(Buckets.map((b) => b.Name));

A sub-user’s key gets an empty list here, even for buckets it can use. Use the bucket name directly.

A presigned URL lets someone download or upload one file without keys, until the link expires. expiresIn is in seconds.

import { GetObjectCommand, PutObjectCommand } from "@aws-sdk/client-s3";
import { getSignedUrl } from "@aws-sdk/s3-request-presigner";
const downloadUrl = await getSignedUrl(
s3,
new GetObjectCommand({ Bucket: "my-bucket", Key: "folder/myfile.txt" }),
{ expiresIn: 3600 },
);
const uploadUrl = await getSignedUrl(
s3,
new PutObjectCommand({ Bucket: "my-bucket", Key: "upload.txt" }),
{ expiresIn: 3600 },
);

If you set a ContentType in the PutObjectCommand, the upload must send exactly that Content-Type header, or Zata answers 403. Anyone who has a link can use it until it expires, so share it only with the intended person.

Troubleshooting

ProblemFix
Large uploads fail with XAmzContentSHA256Mismatch; small files workAdd requestChecksumCalculation and responseChecksumValidation set to "WHEN_REQUIRED".
InvalidAccessKeyIdendpoint is missing (requests go to AWS), or the key is from the other region.
NoSuchBucket for a bucket you can see in the consoleUse the endpoint of the region the bucket is in.
Calling Zata from a web page in the browser fails (CORS)Browser access needs CORS rules for your site. See Browser and SDK access. Do not put keys in browser code: create presigned links on your server instead.

Never set NODE_TLS_REJECT_UNAUTHORIZED=0: Zata’s certificates are valid. For other errors, see Large uploads and Wrong endpoint or region.