Upload File
import { initializeMeshSDK, logResponse } from "./util";
import {
UploadFileRequest,
UploadFileResponse
} from "@instruxi-io/mesh-sdk-core";
async function uploadTestFile(mesh: any): Promise<string | undefined> {
try {
const createBuffer = (content: string): Buffer => {
return Buffer.from(content);
};
const pdfBuffer = createBuffer('PDF content');
const uploadRequest: UploadFileRequest = {
file: pdfBuffer,
file_name: 'test.pdf',
directory_name: '',
bucket: '' // OPTIONAL if Admin
access
};
const response: UploadFileResponse = await mesh.os.uploadFile(uploadRequest);
console.log('File uploaded successfully:', response);
return response.data.file_id;
} catch (error) {
console.error('Error:', error);
if (error instanceof Error) {
console.error('Error message:', error.message);
console.error('Error stack:', error.stack);
}
}
}
async function main() {
try {
const mesh = await initializeMeshSDK();
const fileId = await uploadTestFile(mesh);
console.log("Uploaded", fileId);
} catch (error) {
console.error("An error occurred:", error);
}
}
main().catch((error) => {
console.error("Unhandled error in main function:", error);
process.exit(1);
});
Updated 6 days ago