I'm trying to transfer an image-file and corresponding information via ajax to a groovlet-server.
Problem: I can't get the data out of the HTTPServletRequest obect.
Here is the Javascript-Code that I use to transfer the data:
$("#submitButton").click( function(){
if ( submitButtonCondition == true ) {
//Gathering Data
var enabledValue = false;
if ($("#activate").val()){
enabledValue = true;
}
var metadata = $("#metaTextarea").val();
var inputFile = $("#fileInput")[0].files[0];
// Creating FormData-Object filled with necessary Data
var formData = new FormData();
formData.append('file', inputFile);
formData.append('enabled', enabledValue);
formData.append('metadata', metadata);
// Sending FormData to Server
$.ajax({
type : 'POST',
url : '/createNewEntry.groovy',
contentType: false,
processData: false,
data: formData,
success: function(resultData){
console.log("Upload successful");
},
failure: function(resultData){
console.log("Upload failed");
}
});
}
});
The only way of verifying if data has been send has been accessing the attached reader of the request object: System.out.println(request.reader.text);
Output looks like this:
------WebKitFormBoundaryzNUfRksUAVW2ioCa
Content-Disposition: form-data; name="file"; filename="blatest.png"
Content-Type: image/png
------WebKitFormBoundaryzNUfRksUAVW2ioCa
Content-Disposition: form-data; name="enabled"
true
------WebKitFormBoundaryzNUfRksUAVW2ioCa
Content-Disposition: form-data; name="metadata"
asdfasdfasdf
------WebKitFormBoundaryzNUfRksUAVW2ioCa--
So apparently the data has been transferred?
Still, I'm struggling to get information out of methods getParameter, getParameterMap, getParameterNames, getParameterValues
which all give me no output.