Skip to content
Advertisement

How to get bytecode from selected pdf in angular

I want to extract the bytecode from an file I select (pdf) to save it in my database. But I am always getting the error that my byte is undefined. Could someone look at my code and tell me what is wrong with it?

I tried to use the FileReader but my byte returns undefined, the formdata works fine it shows on the console every information I need for the file.

EDIT:

JavaScript

Hi I edited my code and now I am getting a base64 I think, but one question, it starts like this: data:application/pdf;base64,JVBERi0xLjQKJfbk/N8KM…….”

is the start with data:application/pdf correct or do I have to change something to save it in the database

Advertisement

Answer

I’d suggest you to store the file as a base64 String in your database. This would look as following. With the line number 2 you’re fetching the file from your input event.

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement