Blob data renders as blank doc when sent to server
See original GitHub issueHi,
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:
- Created 3 years ago
- Comments:5
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Found alternative solution
Cool, yeah we almost had the exact same approach 👍