// 1. Upload a material
const fileBuffer = await fs.promises.readFile(
path.join(process.cwd(), 'biology-notes.pdf'),
);
const file = new File([fileBuffer], 'biology-notes.pdf', {
type: 'application/pdf',
});
const material = await client.v1.materials.upload.uploadFile({
file,
name: 'Biology Notes v1'
});
console.log('Uploaded:', material._id);
// 2. Wait for processing
let status = 'processing';
while (status === 'processing') {
await new Promise(resolve => setTimeout(resolve, 2000));
const updated = await client.v1.materials.retrieve(material._id);
status = updated.status;
}
// 3. Rename the material
const renamed = await client.v1.materials.rename(material._id, {
name: 'Biology Notes - Final Version'
});
// 4. Move to a folder
const moved = await client.v1.materials.move(material._id, {
folderId: 'folder_biology'
});
// 5. Get download URL
const { downloadUrl } = await client.v1.materials.getDownloadURL(material._id, {
expiresIn: 3600
});
console.log('Download from:', downloadUrl);
// 6. Eventually delete
// await client.v1.materials.delete(material._id);