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

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

const result = await ns.uploads.upload({
  file: fs.createReadStream("./example.md"),
  contentType: "text/markdown",
});
console.log("Uploaded successfully: ", result.key);

// OR get the pre-signed URL manually
const file = fs.readFileSync("./example.md");
const result = await ns.uploads.create({
  fileName: "example.md",
  fileSize: file.length,
  contentType: "text/markdown",
});

await fetch(result.url, {
  method: "PUT",
  body: file,
  headers: {
    "Content-Type": "text/markdown",
  },
});
console.log("Uploaded successfully: ", 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
fileName
string
required
Minimum length: 1
contentType
string
required
fileSize
number
required
Required range: 1 <= x <= 209715200

Response

Presigned URL generated successfully

success
boolean
required
data
object
required