鍍金池/ 問答/網(wǎng)絡安全  HTML/ nodejs supertest 測試文件上傳功能

nodejs supertest 測試文件上傳功能

1.后臺是http,用的是eggjs,測試普通的get,post是沒有問題的
2.測試文件上傳出現(xiàn)問題

{ Error: read ECONNRESET
    at _errnoException (util.js:1021:11)
    at TCP.onread (net.js:608:25)
  code: 'ECONNRESET',
  errno: 'ECONNRESET',
  syscall: 'read',
  response: undefined }

測試代碼如下

    it('file upload', async () => {
        let data:any = await new Promise(resolve => {
            app.httpRequest().post('/api/company/add')
            .set('Content-Type', 'multipart/form-data')
            .field('companyName', 'supertest')
            .field('projectId', 1)
            .attach('logo', '/zzj1026/Rnx/RaEgg/static/public/user/avator/9bf15f495f976447cde6b422f579f910.jpg')
            .end((err,res) => {
                if(err) console.log(err);
                resolve({status: true, data:res});
            });            
        });
        console.log(data);
    });
回答
編輯回答
澐染

你的后端接口代碼呢?

利用egg上傳文件,是不是得需要egg-multipart插件得配合

2018年2月21日 11:19