I am getting a response of arraybuffer from API for attached PDF documents,I want to preview the pdf document in edit mode and send the same pdf as FileList(like how get file list object when we upload using ). I have managed to convert the array buffer to blob and preview but cant form file list to send it back to api.
arrayBufferToBase64(buffer) {
let binary = '';
const bytes = new Uint8Array(buffer);
const len = bytes.byteLength;
for (let i = 0; i < len; i++) {
binary += String.fromCharCode(bytes[i]);
}
const file = window.btoa(binary);
const byteCharacters = atob(file);
const byteArrays = [];
for (let offset = 0; offset < byteCharacters.length; offset += 512) {
const slice = byteCharacters.slice(offset, offset + 512),
byteNumbers = new Array(slice.length);
for (let i = 0; i < slice.length; i++) {
byteNumbers[i] = slice.charCodeAt(i);
}
const byteArray = new Uint8Array(byteNumbers);
byteArrays.push(byteArray);
}
const blob = new Blob(byteArrays, { type: 'application/pdf' });
const objectURL = URL.createObjectURL(blob);
this.pdfUrl = this.sanitizer.bypassSecurityTrustResourceUrl(objectURL);
}
Expected Output - FileObject
FileĀ {
lastModified: 1573560008286
lastModifiedDate: Tue Nov 12 2019 17:30:08 GMT+0530 (India Standard Time) {}
name: "bill.pdf"
size: 67599
type: "application/pdf"
webkitRelativePath: ""
}