我正在尝试使用Dropzone上传文件。上传调用是对Web Api服务的。但是,浏览器返回以下问题“的XMLHttpRequest无法加载http://localhost:444/api/Controller/Upload/xyz123无‘访问控制允许来源’标头出现在所请求的资源。起源‘http://localhost:53006’因此不允许访问。响应的HTTP状态代码为404。“。
下面列出了我的文件上传实施代码。任何建议都表示赞赏。
var myAwesomeDropzone = new Dropzone("#dropzoneForm", {
acceptedFiles: "application/pdf",
header: {
'Authorization': authorizationToken,
'Cache-Control': null,
'X-Requested-With': null
},
init: function () {
this.on("processing", function (file) {
console.log(app);
this.options.url = apiBaseUrl + "/Controller/Upload/" + id;
});
this.on("addedfile", function (file) {
console.log("added file");
});
this.on("success", function (file) {
console.log("successfully uploaded file");
});
}
});
HTML code:
<form action="http://BaseUrl/Controller/Upload" method="post" enctype="multipart/form-data" class="dropzone" id="dropzoneForm">
<div><span>Click here or drag files to upload</span></div>
<div class="fallback">
<input name="file" type="file" multiple />
<input type="submit" value="Upload" />
</div>
</form>
服务器端代码:
[System.Web.Http.HttpPost]
public async Task<IHttpActionResult> Upload(Guid id)
{
// Upload file
}