question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

.toBuffer() not working with s3.putObject

See original GitHub issue

When I try to write my generated .docx file to s3, everything goes well. But when I download the file from s3 using the public link, my text editor can’t open it as it is base64 encoded string. If I use packer.toBuffer(doc) instead the s3.putObject is not happy and says he requires buffer or base64 string. Why is toBuffer not valid argument for s3.putObject.

...
// set up doc and packer, doc is generated normally I checked
const documentBuffer = await packer.toBase64String(doc);

s3.putObject(
    {
      Bucket: "my-bucket",
      Key: "my-file.docx",
      Body: documentBuffer,
      ACL: "public-read",
      ContentEncoding: "base64",
      ContentType:
        "application/vnd.openxmlformats-officedocument.wordprocessingml.document"
    },
    resp => {
      console.log({ resp });
    }
  );

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
jwerrecommented, Nov 15, 2019

I had the same issue (https://github.com/dolanmiu/docx/issues/379).

You can wrap the “buffer” and it will work:

buffer = await Packer.toBuffer(doc);

s3.putObject({
    Bucket: "my-bucket",
    Key: "my-file.docx",
    Body: Buffer.from(buffer), // wrap here
}, (res) => {
    console.log(res);
});


0reactions
kelvanince21commented, Nov 3, 2021

@dolanmiu Why was this issue closed? It isn’t resolved.

Read more comments on GitHub >

github_iconTop Results From Across the Web

PUT base64 encoded buffer to AWS S3 bucket with ...
I'm fairly certain this is due to a lack of response from AWS due to an incorrectly formatted buffer. I've run into similar...
Read more >
Using an Amazon S3 trigger to create thumbnail images
Amazon S3 invokes the CreateThumbnail function for each image file that is uploaded to an ... Follow these steps to create S3 buckets...
Read more >
Upload paper.js as PNG to Amazon AWS/S3
It looks like my generated paper projects have a different alignment when I write them toBuffer() compared to when I export them as...
Read more >
Amazon S3 - Fluent Bit: Official Manual
The plugin can upload data to S3 using the multipart upload API or using S3 ... help improve throughput when there are transient/random...
Read more >
Storing Images in S3 from Node Server
toBuffer() // Configure the upload details to send to S3 const fileName ... I just also want to bring to your notice that...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found