
[英]How to retain visibly previous uploaded files using ng-file-upload when tried to upload again?
[英]Getting Error Code 405 when uploading files using ng-file-upload
我正在尝试根据此处找到的示例使用ng-file-upload实现文件上传功能。
除了尝试将文件上传到本地Web服务器时,我收到Error Code 405 (Method not allowed)
一切似乎都正常。
这是我的标记的一部分:
<div class="block form-group">
<label for="photo">Photos:</label>
<input type="file" ngf-select ng-model="addCourtCtrl.picFile" name="file"
accept="image/*" ngf-max-size="2MB" required
ngf-model-invalid="errorFile">
<img ng-show="addRegisterForm.file.$valid" ngf-thumbnail="picFile" class="thumb">
<button ng-click="addCourtCtrl.picFile = null" ng-show="addCourtCtrl.picFile">Remove</button>
<br>
<button ng-click="addCourtCtrl.uploadPic(addCourtCtrl.picFile)">
Upload
</button>
<span class="progress" ng-show="addCourtCtrl.picFile.progress >= 0">
<div style="width:{{addCourtCtrl.picFile.progress}}%"
ng-bind="addCourtCtrl.picFile.progress + '%'"></div>
</span>
<span ng-show="picFile.result">Upload Successful</span>
<span class="err" ng-show="errorMsg">{{errorMsg}}</span>
</div>
这是我的上传功能的定义:
this.uploadPic = function (file) {
file.upload = Upload.upload({
url: '/www/images/uploads/courts',
data: { username: __this.username, file: file },
});
file.upload.then(function (response) {
$timeout(function () {
file.result = response.data;
});
}, function (response) {
alert('Upload Failed');
if (response.status > 0)
__this.errorMsg = response.status + ': ' + response.data;
}, function (evt) {
// Math.min is to fix IE which reports 200% sometimes
file.progress = Math.min(100, parseInt(100.0 * evt.loaded / evt.total));
});
}
我正在使用gulp的网络服务器来运行此应用程序,当我使用示例中的相同上传URL时,不会显示错误。
我一直在寻找与此问题相关的一些问题,但是我是Angular的新手,我发现大多数答案都太复杂了。
我希望有人能帮助我。 提前致谢。
您最有可能面临CORS问题。 如果从其他域执行,则来自浏览器的Ajax请求将被拒绝。 您需要将CORS标头添加到您的后端。 请在这里查看更多有关CORS的信息: https : //developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.