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 files.

When a user uploads a file, it is uploaded to the S3 bucket, but when checking the file's content, it is empty(blank file).

Code:
   Back End 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;

Everything is working fine, but getting blank documents in the S3 bucket.
<p>We have a S3 bucket where we upload some files.</p>
<p>When a user uploads a file, it is uploaded to the <code>S3 bucket</code>, but when checking the file's content, it is <strong>empty</strong>(blank file).</p>
<pre><code> Back End 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>Everything is working fine, but getting blank documents in the S3 bucket.</p>
Continue reading...
 

Latest posts

I
Replies
0
Views
1
Isaac P. Liu
I
U
Replies
0
Views
1
user3658366
U
G
Replies
0
Views
1
Giampaolo Levorato
G
M
Replies
0
Views
1
Marcelo Rodrigo Nascimento
M
Top