I am trying to upload a file from a custom form and there are no issues updating other fields except for adding a file. Here are the codes below. Can anybody tell me, what’s wrong with this.
Error: Access to XMLHttpRequest at ‘https://api.monday.com/v2/file’ from origin ‘null’ has been blocked by CORS policy: Response to preflight request doesn’t pass access control check: No ‘Access-Control-Allow-Origin’ header is present on the requested resource.
var url = "https://api.monday.com/v2/file";
var boundary = "------WebKitFormBoundary7MA4YWxkTrZu0gW--";
var data = "";
var payload = "";
// File Reader
var fileReader = new FileReader();
fileReader.onloadend = function (e) {
data += boundary + "\r\n";
data += "Content-Disposition: form-data; name=\"query\"; \r\n";
data += "Content-Type:application/pdf\r\n\r\n";
data += "\r\n" + query + "\r\n";
// construct file part
data += boundary + "\r\n";
data += "Content-Disposition: form-data; name=\"variables[file]\"; filename=\"" + fileName + "\"\r\n";
data += "Content-Type:application/octet-stream\r\n\r\n";
data += e.target.result + "\r\n";
data += ("\r\n" + boundary + "\r\n");
}
fileReader.readAsBinaryString(fileUpload);
$.ajax({
url: url,
method: "POST",
body: data,
headers: {
"Content-Type": "multipart/form-data; boundary=" + boundary,
"Authorization": myToken
}
}).done(function (res) {
console.log(res);
}).fail(function (res) {
console.log(res);
});