0
我設法使用Kendo和AngularJS上傳文件,但是我的文件保持紅色並且有k-file-error類,文件已上傳,我可以將它們放在後面。爲什麼會有錯誤?你可以幫我嗎 ?當kendo上傳成功時k-file-error
<div class="demo-section k-content">
<div>
<h4>Upload files</h4>
<div class="dropZoneElement">Drag and drop file here</div>
<input name="files"
ng-model="vm.files"
type="file"
kendo-upload
k-async="{ saveUrl: 'http://localhost:5000/api/upload/', removeUrl: 'remove', autoUpload: true, withCredentials: false }"
k-select="onSelect"
k-upload="onUpload"
k-progress="onProgress"
k-success="onSuccess"
options="vm.options"
/>
</div>
<button ng-click="vm.test()">Test</button>
</div>
class DocumentController {
/* @ngInject */
constructor($scope, authTokenService) {
this.name = 'document';
$scope.onSelect = e => {
// console.log(e.files);
};
$scope.onUpload = e => {
const token = authTokenService.getToken();
// Check if the token is expire
if (token && authTokenService.isExpired(token)) {
authTokenService.setToken();
}
const xhr = e.XMLHttpRequest;
if (xhr) {
xhr.addEventListener('readystatechange',() => {
if (xhr.readyState === 1) {
// Add the token to the header
if (token) {
xhr.setRequestHeader('Authorization', `Bearer ${token}`);
}
}
});
}
};
$scope.onSuccess = e => {
console.log(e);
};
$scope.onProgress = e => {
// console.log(e);
};
this.options = {
dropZone: '.dropZoneElement'
};
}
}
export default DocumentController;
你的服務器動作(http:// localhost:5000/api/upload)返回什麼?所有的上傳演示都有這個:「//返回一個空字符串表示成功」。 –