Franceska Hoxha
Franceska Hoxha4mo ago

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?
3 Replies
Deno AI Helper
Deno AI Helper4mo ago
I wasn't able to find the answer to your question in the official Deno documentation. However, based on the code snippet you provided, there is a syntax error in your logging statement. The line:
("Uploading file to S3 with filePath:", filePath);
("Uploading file to S3 with filePath:", filePath);
appears to be missing a console.log or similar logging function. It should be:
console.log("Uploading file to S3 with filePath:", filePath);
console.log("Uploading file to S3 with filePath:", filePath);
Please note that this advice is not based on the Deno documentation, and I would advise you to double-check the accuracy of the advice given. If the issue persists after correcting the syntax error, you may want to review the deno-s3-lite-client documentation or source code for more details on how to use the putObject method correctly, especially regarding setting the content type in the metadata.
jordanbtucker
jordanbtucker4mo ago
Are you getting any error messages?
Franceska Hoxha
Franceska Hoxha4mo ago
No error messages, just the fike uploaded successfully but not with the type filed. So when i try to open it, it wont open becase it doesnt have a type