Welcome to OGeek Q&A 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 Reply

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...