上载失败时,使用dropzone-react-component设置重试

问题描述

在我的项目中,我使用的是基于Dropzone.js的React-Dropzone-Componenthttps://github.com/felixrieseberg/React-Dropzone-Component)。 我之所以使用此组件,是因为我正在开发SharePoint Webpart,并且在Microsoft PnP GitHub存储库上已经有一个基于此解决方案的示例。

无论如何,上传工作正常,但是有时,主要是当我打开网页几分钟后,什么也不做时,收到尝试上传文件错误。我重试上传,但失败,返回错误Server responded with (0) code。我还在Google Chrome控制台上看到一个ERR_CONNECTION_RESET错误。如果我尝试在第二个实例中上传5个文件,则我会在第一个2-3个错误,然后其余文件工作正常。很奇怪。

我已经调查了我的网络,但是没有失败。我还尝试了3种不同的网络,但收到了相同的错误

我还使用最新的Dropzone.js(5.7.2)更新了该组件。

这是我的代码

    let componentConfig = {
      iconFiletypes: this.props.fileTypes.split(','),showFiletypeIcon: true,postUrl: _context.pageContext.web.absoluteUrl,autoprocessQueue: true
    };
    var djsConfig = {
      headers: {
        "X-RequestDigest": digest1
      },addRemoveLinks:false
    };
    let myDropzone;
    let eventHandlers = {
      // This one receives the dropzone object as the first parameter
      // and can be used to additional work with the dropzone.js
      // object
      init: function(dz){       
       myDropzone=dz;
      },sending: async function (file,xhr) {
        var fileName = file.name;
        fileName = fileName.replace(/[&\/\\#,+()$~%='":*?<>{}]/g,"");  
        if (file.size <= 10485760) {
            // small upload
            await web.getFolderByServerRelativeUrl("/test/"+_listName).files.add(fileName,file,true).then(_ => console.log("Ok!"));
        } else {
            // large upload
            await web.getFolderByServerRelativeUrl("/test/"+_listName).files.addChunked(fileName,data => {},true).then(_ => console.log("Ok!"));
        }
      },error:function(file,error,xhr){
        file.status = myDropzone.ADDED;
        myDropzone.removeFile(file);
        myDropzone.enqueueFile(file);
      }
     };

     <DropzoneComponent eventHandlers={eventHandlers} djsConfig={djsConfig} config={componentConfig}>
        <div className="dz-message icon ion-upload">Drop files here to upload</div>  
     </DropzoneComponent>

如果无法阻止此ERR_CONNECTION_RESET错误,我想为这些文件设置自动重试。我上面发布的代码无法正常工作,或者返回"Uncaught Error: This file can't be queued because it has already been processed or was rejected."

是否有解决方案或设置重试的好方法

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)