Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.7k views
in Technique[技术] by (71.8m points)

getting [object Object] as the file content after downloading a file in angular

I am able to download a file using filesaver however the content I am getting is [object Object], I tried using responseType: "blob" as "blob"/"json" but the response is changing to undefined but not the file content. any suggestions?

getBlobChunk(fileSize: number, userRole: String, inFileName: String, inFilePath: String) {
let chunks = [{}];
const chunkSize = 1024 * 1024 * 20; // 20 MB each chunk
let j = 0;
for (let index = 0; index < fileSize; index += chunkSize + 1) {
chunks[j++] = { startRange: index, endRange: index + chunkSize > fileSize ? fileSize : index + chunkSize };
}
let headers = [];
for (let chunkIndex = 0; chunkIndex < chunks.length; chunkIndex++) {
const chunk = chunks[chunkIndex];
//   const rangeVal = 'bytes=' + chunk['startRange'] + '-' + chunk['endRange'];
const httpHeaders = new HttpHeaders().append('startrange', chunk['startRange']).append('endrange', chunk['endRange']);
headers.push(
this.httpClient.post(url, {
userrole: userRole,
srcfileName: inFileName,
srcfilePath: inFilePath
}, { headers: httpHeaders,responseType: 'blob' as 'blob', reportProgress: true, observe: 'events' })
.pipe(
map((event: any) => {
if (event.type === HttpEventType.DownloadProgress) {
some code...
}
})
)
);
}
return forkJoin(headers);
}

note: I can see the file content under response tab


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...