Node.js 使用angular/http模块时文件在angular中损坏
我正在使用文件保护程序和angular/http。上传、删除到s3存储桶工作正常,但当我下载文件时,它显示文件已损坏,文件大小非常小(50B) }Node.js 使用angular/http模块时文件在angular中损坏,node.js,angular,amazon-s3,Node.js,Angular,Amazon S3,我正在使用文件保护程序和angular/http。上传、删除到s3存储桶工作正常,但当我下载文件时,它显示文件已损坏,文件大小非常小(50B) } [回复。_body]解决了问题是命中错误消息还是成功?什么是saveAs函数?您可能需要这个.saveAs(…它没有出现错误消息,文件正在下载,但内容不完整。我尝试了这个.saveAs它不工作。saveAs是从文件保存程序导入的 dowlnoad(attachment){ var filename = attachment.uploadname;
[回复。_body]解决了问题是命中错误消息还是成功?什么是saveAs函数?您可能需要
这个.saveAs(…
它没有出现错误消息,文件正在下载,但内容不完整。我尝试了这个.saveAs它不工作。saveAs是从文件保存程序导入的
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;
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;
}