[英]ungzip not working with axios on post request
我想壓縮大量字符串數據,並希望登錄到文件並下載此文件,以便將來可以在需要時使用該數據,為此我選擇了“gzip-node”。 我可以 zip 字符串並存儲到文件中,但在解壓縮時,它顯示以下錯誤
(node:71720) UnhandledPromiseRejectionWarning: Error: Error: incorrect header check
[0] at Gunzip.cb (C:\Users\nagasudha.sanikommu\project-omega - Copy (4) - Copy\node_modules\node-gzip\dist\index.js:17:49)
[0] at Gunzip.zlibBufferOnError (zlib.js:119:8)
[0] at Gunzip.emit (events.js:209:13)
[0] at Zlib.zlibOnError [as onerror] (zlib.js:173:8)
[0] (node:71720) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 5)
[0] Promise { <pending> }
app.post('/open',function(request,response,next){
console.log(request);
if(request.files.selectedFile){
let file=request.files.selectedFile;
let dest=__dirname+'/uploads/example.txt';
file.mv(dest,function(err){
if(err){
response.send("File not found");
}
else{
fs.readFile(__dirname+'/uploads/example.txt',function(err,data){
ungzip(data.toString()).then((u)=>{
response.send(u);
})
})
}
})
}
})
handleFileOpen=function(event) {
let data=new FormData();
data.append('selectedFile',event.target.files[0]);
axios({
method:"post",
url:"http://localhost:4001/open",
data:data,
})
.then(res=>{
console.log(res.data);
})
您需要像這樣請求通過Header
axios.post('http://localhost:4001/open', data,
{
responseType: 'arraybuffer',
headers: {
'Content-Type': 'multipart/form-data',
}
})
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.