Can anyone help me with extracting the bytecode from a selected PDF file to save it in my database? I keep encountering an error stating that my byte is undefined. Could someone please review my code and identify what might be causing this issue?
I attempted to use the FileReader function, but unfortunately, my byte remains undefined. On the other hand, the FormData appears to be working properly as it displays all the necessary file information on the console.
EDIT:
uploadFile2(files: FileList | null): void {
const file = files.item(0)
const reader = new FileReader()
reader.readAsDataURL(file)
reader.onload = () => {
this.documentsArray.push({documentType: this.form.controls.dokumentType.value, file: reader.result})
console.log(this.documentsArray)
}
}
I have updated my code and now seem to be receiving a base64 output. However, one question still remains - the data starts with: data:application/pdf;base64,JVBERi0xLjQKJfbk/N8KM......."
Should the initial data value of 'data:application/pdf' remain as is or should I make changes before saving it to the database?