I am doing some exercise in Play Framework(2.2.3) now a days. I wanted to upload a file and save it in play framework server path on single click button using jquery and ajax. So, if I know that file uploaded path in jQuery, I can use it in my application. Please let me know how to achieve this ? I have done something like the below, as I don't know where my file is uploaded and it should be stored in my play server.
html:
<span>File</span>
<input type="file" id="file" name="file" size="10"/>
<input id="uploadbutton" type="button" value="Upload"/>
jquery+ajax:
$(document).ready(function () {
$("#uploadbutton").click(function () {
//var filename = $("#file").val();
var filename = $("#file").val().replace(/C:\\fakepath\\/i, '');
console.log("filename: "+filename);//uploaded file names
$.ajax({
type: "POST",
url: "/upload",
enctype: 'multipart/form-data',
data: {
file: filename
},
success: function () {
alert("File is Uploaded: ");// where it is uploaded ?
},
error: function (xhr, ajaxOptions, thrownError) {
console.log(xhr.status);
console.log(xhr.responseText);
}
});
});
});