I'm sending an http request to my express server that gets a file from an s3 bucket and returns it. But when I return the file I get an error:
error: SyntaxError: Unexpected token % in JSON at position 0. The payload when looked at in preview looks something like:
%PDF-1.7
%¡³Å×
1 0 obj
<</Pages 2 0 R /Type/Catalog/ViewerPreferences<</Direction/L2R>>>>
endobj
2 0 obj
<</Count 5[ 4 0 R 22 0 R 40 0 R 51 0 R 54 0 R ]/Type/Pages>>
endobj
3 0 obj
<</CreationDate(D:20210621163020)/Creator(PDFium)/Producer(PDFium)>>
So I think the file stream is coming through properly but I can't seem to do anything with it to stop the errors, it seems like it's trying to parse the payload as json (which is obviously failing). I just want to store the incoming file so I'm either able to write it to disk or download it..
getFile(filename): Observable<any> {
const headers = new HttpHeaders({ 'Content-type': 'application/pdf' });
return this.http.get(`someendpoint/download/${filename}`, { headers: headers })
.pipe(
catcherror(err => { return throwerror(err); })
)
);
}
testGet() {
const name = 'test.pdf';
getFile(name).subscribe((res) => {
console.log(res);
});
}
Seriously stuck right now, any help would be greatly appreciated!