Im trying to make a upload form, where you can select multiple(max5) images and then I scale them to be 600px wide before uploading, with load-image.js, exif.js,load-image-scale.js, load-image-orientation.js. Im using the Persits.Upload component on my server to save the images.
If I send images directly from the form(not with ajax in my js file) then it works as it should.
But if I select 5 images on the phone it takes about 18seconds to upload them, so therefor I would like to scale them down to 600px wide before I upload them. And that´s why I would like to send them with formData instead.
When You have selected the images I show a thumbnail preview that is 100px heigh.
Im trying to appen the scaled image to new FormData
that Im sending to my server with ajax request.
My form looks like this.
<form action="#" id="sparauploads" ENCTYPE="multipart/form-data" autocomplete="off">
And my ajax request looks like this.
var formElement;
var formData;
formElement = document.getElementById('sparauploads')
console.log('formElement'+formElement)
formData = new FormData(formElement)
var data;
app.request({
method: 'POST',
url: 'uploadimages/uploadimages2.asp',
data: formData,
//header: 'Content-Type', 'multipart/form-data',
cache: false,
dataType: 'application/json',
mimeType: 'multipart/form-data',
contentType:'multipart/form-data',
processData: true,
beforeSend: function ( xhr ) {
xhr.setRequestHeader( 'Content-type', 'multipart/form-data');
console.log(JSON.stringify(xhr), "BEFORE SEND");
app.dialog.alert(JSON.stringify(xhr), "BEFORE SEND");
},
success: function (data) {
console.log(data)
return false;
}
});
And the first problem I get is this error in my server page that are suppose to save the images.
Boundary not found in Content-Type. Make sure you have included the attribute ENCTYPE="multipart/form-data" in your form.
And when I look at the console.log(JSON.stringify(xhr), "BEFORE SEND");
I get this.
{"requestUrl":"uploadimages/uploadimages2.asp","requestParameters":{"url":"uploadimages/uploadimages2.asp","method":"POST","async":true,"cache":false,"user":"","password":"","headers":{},"xhrFields":{},"statusCode":{},"processData":true,"dataType":"application/json","contentType":"application/x-www-form-urlencoded","timeout":0,"mimeType":"multipart/form-data","crossDomain":false}} – "BEFORE SEND"
As I can tell I have set the enctype correctly with multipart/form-data?
So why is is saying that Im not sending the form with multipart/form-data?
Any input really appreciated, and also if anybody has done this before please share Thanks a lot!