What is the problem?
Uploading a file through the API using javascript
What did you already try to solve it?
I tried the following JS code
$.ajax({
url : "http://" + host + "/api/files/sdcard",
type : 'POST',
data : formData,
processData: false,
contentType: "multipart/form-data",
beforeSend: function(request) {
request.setRequestHeader("X-Api-Key", key);
},
success : function(data) {
console.log(data);
alert(data);
},
error: function(data) {
console.log(data);
alert("Error. Check console");
},
failure: function(data) {
console.log(data);
alert("Error. Check console");
}
});
I also tried uploading the file using postman as a testing-environment, I tried all sorts of different combinations;
images on imgur, as "new users" only can upload one image
In Postman, when having the "Content-Type" set to "multipart/form-data", it "shuts down" my request immediately (saying "Could not get any response"), but when having it set to "application/x-www-form-urlencoded" it seems like it actually sends the file, as it takes some time before giving me the "No file to upload and no folder to create" error-message.
Additional information about your setup (OctoPrint version, OctoPi version, printer, firmware, octoprint.log
, serial.log
or output on terminal tab, ...)
octoprint.log (6.5 KB)
Any help appriciated I followed the "File operations" docs instructions quite carefully, and I can't really see what I've done wrong.