1
MVC部分從MVC控制器返回excel文件和從angularJS下載它在POST請求
返回文件(流, 「應用程序/ vnd.ms-EXCEL」,file.FileName);
我以上述方式從MVC控制器返回文件。
AngularJS控制器
$scope.ExcelValidate = function() {
if ($scope.files && $scope.files.length && $scope.selectedFileType != -1) {
busyIndicatorService.showBusy("Uploading data...");
for (var i = 0; i < $scope.files.length; i++) {
var file = $scope.files[i];
$scope.file = file.name;
Upload.upload({
url: '/MasterExcelImport/ValidateExcelData',
fields: {
uploadType: $scope.selectedFileType.Key.Key
},
file: file
}).progress(function (evt) {
console.log('percent: ' + parseInt(100.0 * evt.loaded/evt.total));
$scope.file.progress = parseInt(100.0 * evt.loaded/evt.total);
}).success(function (data) {
busyIndicatorService.stopBusy();
var blob = new Blob([data], { type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" });
var objectUrl = URL.createObjectURL(blob);
window.open(objectUrl);
}).error(function (data, status, headers, config) {
busyIndicatorService.stopBusy();
});
}
}
};
返回文件已經談到的成功部分。但下載部分失敗了。
有人可以幫我解決這個問題嗎?
感謝, Erandika Sandaruwan
你得到的base64字符串作爲HTTP調用 –
什麼錯誤訊息的結果你得到了嗎? – georgeawg