I am trying to upload file using Dropzone. The upload call being made to a Web Api service. But, the browser returns the following issue "XMLHttpRequest cannot load http://localhost:444/api/Controller/Upload/xyz123. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:53006' is therefore not allowed access. The response had HTTP status code 404.".
Below listed my file upload implementation code. Any suggestion is appreciated.
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>
Server side code:
[System.Web.Http.HttpPost]
public async Task<IHttpActionResult> Upload(Guid id)
{
// Upload file
}