OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Uploading File to S3 via Node.js SDK Resulting is blank file

  • Thread starter Thread starter Not A Bot
  • Start date Start date
N

Not A Bot

Guest
We have a S3 bucket where we upload some file.

When user uploads file, that files is uploaded to S3 bucket, but when checking the content of the file, it is empty(blank file).

Code:
   // Importing modules
   import { PutObjectCommand, S3Client } from '@aws-sdk/client-s3';
   
  // Setting up S3 client
   const s3 = new S3Client({
     credentials: {
       accessKeyId: process.env.ACCESS_KEY_ID as string,
       secretAccessKey: process.env.SECRET_ACCESS_KEY as string,
    },
    region: s3Info.S3_REGION,
   });

   const pdfContent = Buffer.from(file[0].buffer);
   const params = {
          Bucket: s3Info.S3_BUCKET_NAME,
          Key: getFilePath(fileName),
          Body: pdfContent,
          ContentType: file[0].mimetype,
   };

   // Uploading the document.
   const command = new PutObjectCommand(params);

   const res = await s3.send(command);
   return fileName;

Eveyting is working fine, but getting blank document in S3 bucket.

<p>We have a S3 bucket where we upload some file.</p>
<p>When user uploads file, that files is uploaded to S3 bucket, but when checking the content of the file, it is empty(blank file).</p>
<pre><code> // Importing modules
import { PutObjectCommand, S3Client } from '@aws-sdk/client-s3';

// Setting up S3 client
const s3 = new S3Client({
credentials: {
accessKeyId: process.env.ACCESS_KEY_ID as string,
secretAccessKey: process.env.SECRET_ACCESS_KEY as string,
},
region: s3Info.S3_REGION,
});

const pdfContent = Buffer.from(file[0].buffer);
const params = {
Bucket: s3Info.S3_BUCKET_NAME,
Key: getFilePath(fileName),
Body: pdfContent,
ContentType: file[0].mimetype,
};

// Uploading the document.
const command = new PutObjectCommand(params);

const res = await s3.send(command);
return fileName;
</code></pre>
<p>Eveyting is working fine, but getting blank document in S3 bucket.</p>
 

Latest posts

Online statistics

Members online
0
Guests online
4
Total visitors
4
Top