I am trying to encode a PDF with BSON, pass the buffer into MongoDB via Mongoose, and then fetch the data from the database, deserialize it, and render the PDF using react-pdf. However, I am currently getting the following error:
Error: Invalid parameter object: need either .data, .range or .url
Based on my troubleshooting, it would seem that my problem is coming from the process of encoding/decoding. Before I encode, this is my PDF file:
- File {name: “9 Of The Most Popular Project Management Methodologies.pdf”, lastModified: 1599512408120, lastModifiedDate: Mon Sep 07 2020 17:00:08 GMT-0400 (Eastern Daylight Time), webkitRelativePath: “”, size: 494879, …}
- lastModified: 1599512408120
- lastModifiedDate: Mon Sep 07 2020 17:00:08 GMT-0400 (Eastern Daylight Time) {}
- name: “9 Of The Most Popular Project Management Methodologies.pdf”
- size: 494879
- type: “application/pdf”
- webkitRelativePath: “”
- proto: File
You’ll notice the File prototype and also that it is labelled “File” at the start (I’m not sure what that label is called).
Now, after I have decoded it, this is the file:
- {name: “9 Of The Most Popular Project Management Methodologies.pdf”, lastModified: 1599512408120, lastModifiedDate: Mon Sep 07 2020 17:00:08 GMT-0400 (Eastern Daylight Time), webkitRelativePath: “”, size: 494879, …}
- lastModified: 1599512408120
- lastModifiedDate: Mon Sep 07 2020 17:00:08 GMT-0400 (Eastern Daylight Time) {}
- name: “9 Of The Most Popular Project Management Methodologies.pdf”
- size: 494879
- type: “application/pdf”
- webkitRelativePath: “”
- proto: Object
As you can see, it is now just a generic object.
Is there a way to encode/decode a PDF file (or any file) while maintaining this prototype information? Am I perhaps doing something else wrong? React-PDF should be working regardless, as I’m pretty sure the object still has a .data parameter… Though I will double check that. I know the file must because it renders fine before I encode it.
Any and all help is very much appreciated!