我正在使用文件保护程序和angular / http。上传,删除到s3存储桶效果很好,但是当我下载文件时显示损坏,文件大小很小(50B)
dowlnoad(attachment){
var filename = attachment.uploadname;
console.log(filename);
this.service.downloadFile(filename)
.subscribe(
data => saveAs( new Blob([data], { type: 'application/octet-stream'
}),filename),
error=> console.error(error)
)
return false;
}
答案 0 :(得分:-1)
downloadFile(file: string){
var body = {filename:file};
let headers = new Headers({ 'Content-Type': 'application/json', 'Accept': 'application/pdf' });
let options = new RequestOptions({ headers: headers, responseType: ResponseContentType.Blob });
this.http.post(`${environment.queryApi}/api/dfile`, body, options).toPromise()
.then(response => this.saveToFileSystem(response,body));;
}
private saveToFileSystem(response,body) {
// const contentDispositionHeader: string = response.headers.get('Content-Disposition');
// const parts: string[] = contentDispositionHeader.split(';');
// const filename = parts[1].split('=')[1];
const blob = new Blob([response._body], { type: 'application/pdf' });
saveAs(blob, body.filename);
return false;
}
[response._body]解决了该问题