2013-10-07 48 views
0

我有差異位置1.Upload1.abc.com 2.upload2.abc.com多個保險庫。如果文件無法上傳,我想在Upload1.abc.com上發帖,將再次啓動整個過程以將文件發佈到Upload2.abc.com我想如果文件上傳失敗後重試到另一個網址

以便文件上傳不會失敗。即使一個塊會再次失敗,整個設置會在運行時上傳到下一個回退URL。

回答

0

這當然是處理失敗上傳的有趣方式。有沒有辦法確保1.Upload1.abc.com總是起來?

我會對Fine Uploader拋出的complete事件做出反應。如果responseJSONsuccess屬性,是true然後彈出端點的新端點疊加,發出setEndpoint電話,終於發出retry調用,這樣上傳重啓,像這樣,

var original_endpoints = ['1.Upload1.abc.com', '2.upload2.abc.com'] 
    , endpoints = original_endpoints; 

var fu = new qq.FineUploader({ 
    // ... Other options 
    cors: { 
    expected: true // this *must* be a cross-origin request 
    }, 
    request: { 
    endpoint: endpoints.shift() // the original endpoint to be attempted first 
    }, 
    callbacks: { 
    onComplete: function (fileId, fileName, responseJSON, xhr) { 
     if (responseJSON.success != true) { 
      var endpoint = endpoints.shift(); 
      if (endpoint !== undefined) { 
      // Changes endpoint for *all* subsequent uploads 
      this.setEndpoint(endpoint); 

      // Or, to change the endpoint for this particular file that failed 
      // and try the original endpoint again on the next file, 
      // this.setEndpoint(endpoints, fileId); 
      } else { 
      // This will restart the process by setting the endpoints queue to 
      // its default. Note that you may want to handle the error of all 
      // endpoints failing another way, as this just restarts the process 
      // and may result in an infinite loop if all endpoints are constantly down. 
      endpoints = original_endpoints; 
      this.setEndpoint(endpoints.shift()); 
      } 

      this.retry(fileId); // Retry the upload 

     } 
    } 
    } 
});