Franceska HoxhaF
Denoβ€’2y agoβ€’
3 replies
Franceska Hoxha

Uploading Files to S3 Bucket usign deno-s3-lite-client

Hello, I have been trying to make a file upload controller with deno's s3 lite client but I am facing an issue with uploading the content type of my file. In their documentation, i can read that the way to use the putObject() fucntion is like this:

Deno.test({ name: "putObject() can stream a large file upload", fn: async () => { // First generate a 32MiB file in memory, 1 MiB at a time, as a stream const dataStream = ReadableStream.from(async function* () { for (let i = 0; i < 32; i++) { yield new Uint8Array(1024 * 1024).fill(i % 256); // Yield 1MB of data } }()); const key = "test-32m.dat"; const metadata = { "Content-Type": "test/streaming", "x-amz-meta-custom-header": "This is a custom value!" }; const response = await client.putObject(key, dataStream, { partSize: 5 * 1024 * 1024, metadata }); assertEquals(response.etag, "ca6d977b6e7dc87ab5c5892e124c7277-7"); const stat = await client.statObject(key); assertEquals(stat.metadata, metadata); }, });

And in my code I have it like this:

try { // Read the file as an ArrayBuffer const buffer = await fileData.arrayBuffer(); // Convert ArrayBuffer to Uint8Array const fileArrayBuffer = new Uint8Array(buffer); ("Uploading file to S3 with filePath:", filePath); // Use contentType option to set the Content-Type header directly const metadata = { "Content-Type": fileData.type, }; // Upload the file using the S3 client await s3Client.putObject(filePath, fileArrayBuffer, { metadata}); console.log("Upload successful"); // Verify the uploaded file's metadata const stat = await s3Client.statObject(filePath); console.log("Uploaded file metadata:", stat.metadata); return filePath;

Can you tell where the problem is from here?
Was this page helpful?