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));