ungzip не работает с топором ios по запросу - PullRequest
0 голосов
/ 29 апреля 2020

Я хочу сжать большое количество строковых данных и хочу войти в файл и загрузить этот файл, чтобы я мог использовать эти данные в будущем по мере необходимости, когда я выбрал «gzip-node». Я могу заархивировать строку и сохранить в файл, но при распаковке она показывает следующую ошибку

(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> }

nodejs код

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);
                    })
                })
            }
        })

    }

})

реагирует js код

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);
  })

1 Ответ

0 голосов
/ 30 апреля 2020

Вам нужно передать Header с таким запросом, как этот

axios.post('http://localhost:4001/open', data,
    {
        responseType: 'arraybuffer',
        headers: {
            'Content-Type': 'multipart/form-data',
        }
    })
...