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.

Blob data renders as blank doc when sent to server

See original GitHub issue

Hi,

I’m rendering a pdf document on a client, which I then subsequently want to sent to a storage server. The PDF displays correctly on the browser (using the URL object) but when the blob data is sent to the server using formdata the pdf renders as a blank page.

Client Code:

<BlobProvider document={doc} filename={filename}>
        {({ blob, url, loading }) => (
          !loading && <FontAwesomeIcon icon={faFileDownload} onClick={() =>  sendToServer(blob) }/>)}
</BlobProvider>

const sendToServer = (blob) => {
    var formData = new FormData();
    formData.append('pdf', blob);

    fetch('/files', {
      method: 'POST',
      body: formData,
    })
  };

Server Code:

var upload = multer();
var processUpload = upload.single('pdf');

app.post('/files', processUpload, function(req, res) {
  fs.writeFileSync('buffer.pdf', req.file); // or req.file.buffer

  // file is a valid, but blank pdf
});

Am I doing something wrong in encoding the file or not waiting for the render to finish? I can’t see what it is. If I examine the pdf on the server side I can see the meta data has correctly been written by react-pdf so I don’t believe its getting corrupted on the fly.

Many thanks, Darragh

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5

github_iconTop GitHub Comments

3reactions
darraghpjonescommented, Jul 3, 2020

Found alternative solution

1reaction
makeupsomethingcommented, Oct 31, 2020

Cool, yeah we almost had the exact same approach 👍

Read more comments on GitHub >

github_iconTop Results From Across the Web

PDF is blank when downloading using javascript
i fetched the data from server as string(which is base64 encoded to string) and then on ... createObjectURL(pdfBlob) const link = document.
Read more >
Solved: PDF Returned from HTTP Response is Blank
I suspect the problem is that the server is not returning the PDF file correctly, although the problem could instead or also be...
Read more >
Blank pdf created while exporting BLOB to pdf file on unix server
Hi, I'm trying to export a blob from DB and write to a pdf file on unix server. But what I'm getting is...
Read more >
PDF macro is rendered with blank page when used with ...
After the upgrade to 5.3, there are some pdf files which are being rendered blank by the pdf macro. This works without problems...
Read more >
ActiveStorage::Blob - Rails API
Blobs are intended to be immutable in as-so-far as their reference to a specific file goes. You're allowed to update a blob's metadata...
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