Skip to main content
POST
/
v1
/
namespace
/
{namespaceId}
/
uploads
/
batch
TypeScript
import { Agentset } from "agentset";
import fs from 'fs';

const agentset = new Agentset({ apiKey: 'agentset_xxx' });
const ns = agentset.namespace('ns_xxx');

const results = await ns.uploads.uploadBatch([
  {
    file: fs.createReadStream("./example-1.md"),
    contentType: "text/markdown",
  },
  {
    file: fs.createReadStream("./example-2.md"),
    contentType: "text/markdown",
  },
]);
console.log("Uploaded successfully: ", results.map((result) => result.key));

// OR get the pre-signed URLs manually
const file1 = fs.readFileSync("./example-1.md");
const file2 = fs.readFileSync("./example-2.md");

const results = await ns.uploads.createBatch({
  files: [
    {
      fileName: "example-1.md",
      fileSize: file1.length,
      contentType: "text/markdown",
    },
    {
      fileName: "example-2.md",
      fileSize: file2.length,
      contentType: "text/markdown",
    },
  ],
});

await Promise.all([file1, file2].map(async (file, i) => {
  await fetch(results[i]!.url, {
    method: "PUT",
    body: file,
    headers: {
      "Content-Type": "text/markdown",
    },
  });
}));

console.log("Upload URLs:", results.map((result) => result.key));
{
  "success": true,
  "data": [
    {
      "url": "<string>",
      "key": "<string>"
    }
  ]
}

Authorizations

Authorization
string
header
required

Default authentication mechanism

Path Parameters

namespaceId
string
required

The id of the namespace (prefixed with ns_)

Examples:

"ns_123"

Body

application/json
files
object[]
required
Required array length: 1 - 100 elements

Response

Presigned URLs generated successfully

success
boolean
required
data
Upload Result · object[]
required