I am working on Angular with PDF upload and download.
html:
<h1>Upload and Download File</h1>
<input type="file" class="upload_file" id="customFile" name="datasource_upload" id="datasource_upload"
accept=".xlsx,.xls,.csv" ngf-max-size="20MB" fd-input (change)="selectFile($event)" />
<button class="btn btn-primary" [disabled]="!selectedFiles" (click)="upload()">
Submit Document
</button>
service.ts:
docUploadRequestURL: Function = (data: any): Observable<any> => {
return this._http.post('/api/upload',data, this.options);
};
fireDownloadFilenetPdfServiceCall: Function = (requestParms: any) => {
const isWindowOpen = requestParms[0].operation === 'PDF_FILENET_SAVE';
if (!isWindowOpen) {
this.win = window.open('', '_blank');
this.win.document.write(
'<div style="margin: 200px auto; width: 300px;"><span style="float: left; padding-right: 15px;"><img src="https://online.citi.com/JFP/images/widgets/jfpw-spinner-medium.gif"></span><span style="float: left; line-height: 32px; font-size: 18px;">Loading... Please wait</span></div>'
);
}
return this._http
.post('/api/pdfDownload', requestParms, this.options)
.subscribe((response: any) => {
if (!isWindowOpen && response) {
var contentType = 'application/pdf';
requestParms.forEach((element: any) => {
let blob = this.b64toBlob(
response[element.AppId].pdfContent,
contentType
);
saveAs(blob, 'loannote.PDF');
});
this.win.close();
}
else{
console.log("PDF saved");
}
});
};
b64toBlob(b64Data: string, contentType: string, sliceSize?: number) {
contentType = contentType || '';
sliceSize = sliceSize || 512;
var byteCharacters = atob(b64Data);
var byteArrays = [];
for (var offset = 0; offset < byteCharacters.length; offset += sliceSize) {
var slice = byteCharacters.slice(offset, offset + sliceSize);
var byteNumbers = new Array(slice.length);
for (var i = 0; i < slice.length; i++) {
byteNumbers[i] = slice.charCodeAt(i);
}
var byteArray = new Uint8Array(byteNumbers);
byteArrays.push(byteArray);
}
var blob = new Blob(byteArrays, { type: contentType });
return blob;
}
When I am downloading PDF and opening it in Chrome, I am getting the following error: