错误:将文件上传到服务器时流意外结束(反应本机fs)

时间:2018-12-13 08:13:49

标签: javascript android react-native file-upload upload

我正在使用react-native-fs将文件(图像)上传到服务器

在后端,我正在使用laravel 5

这是上传文件的代码(应该与其文档上的内容相同)

async uploadImageReq(){
    var url = this.API_BASE_URL + '/api/addimages/'
    var uploadBegin = (response) => {
      var jobId = response.jobId;
      console.log('UPLOAD HAS BEGUN! JobId: ' + jobId);
    };

    var uploadProgress = (response) => {
      var percentage = Math.floor((response.totalBytesSent/response.totalBytesExpectedToSend) * 100);
      console.log('UPLOAD IS ' + percentage + '% DONE!');
    };
    console.log('check url', url, files) 
    return await RNFS.uploadFiles({
      toUrl: url,
      files: files,
      method: 'POST',
      headers: {
        'Accept': 'application/json',
        'Authorization': 'Bearer ' + this._sessionToken,
        'Connection': 'close'
      },
      fields: {
        'hello': 'world',
      },
      begin: uploadBegin,
      progress: uploadProgress
    }).promise.then((response) => {
        console.log('result', response)
        return response
        if (response.statusCode == 200) {
          console.log('FILES UPLOADED!'); // response.statusCode, response.headers, response.body
        } else {
          console.log('SERVER ERROR');
        }
      })
      .catch((err) => {
        if(err.description === "cancelled") {
          // cancelled by user
        }
        console.log('ERROR',err);
      })
  }

此抛出错误

  

[错误:流的意外结束] framesToPop:1,代码:“ EUNSPECIFIED”

您知道是什么原因导致此错误吗?

1 个答案:

答案 0 :(得分:0)

在我的情况下,Error: Socket is closed, code: 'EUNSPECIFIED'表示文件名有误。