2017-10-17 29 views
0

任務是使在瀏覽器中的文件,然後上傳到服務器上。 我已經創建了blob對象,然後在瀏覽器中創建了文件對象,然後將其上載到服務器上。File對象無法上傳到服務器在Safari

var file = [new File([data],'-Invoice.pdf', {type: 'application/pdf;charset=utf-8;'})]; 

在safari中成功創建文件,但當我要求上傳時,服務器用404 i-e文件未找到錯誤回覆我。 在Chrome/Firefox中完美工作。 在服務器端使用npm模塊express-fileupload。 請幫我

回答

0

在瀏覽器的差異應該不會影響到服務器端上傳。在打電話給服務器時,應該仔細檢查是否有該文件。

我假設你沒有使用自己的文件上傳按鈕。嘗試按照他們的HTML上傳指南,它應該工作,雖然我還沒有在Safari中測試過。

$scope.upload = function (file) { 
console.log(file.length); // if less than 1 or undefined, then your problem is probably in the html. I 
    Upload.upload({ 
     url: 'upload/url', 
     data: {file: file, 'username': $scope.username} 
    }).then(function (resp) { 
     console.log('Success ' + resp.config.data.file.name + 'uploaded. Response: ' + resp.data); 
    }, function (resp) { 
     console.log('Error status: ' + resp.status); 
    }, function (evt) { 
     var progressPercentage = parseInt(100.0 * evt.loaded/evt.total); 
     console.log('progress: ' + progressPercentage + '% ' + evt.config.data.file.name); 
    }); 
}; 
+0

我想它已經,但問題仍然存在。 –

相關問題