2

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);
                      }
                });
            });
        });
2
  • I used your example as a solution to another problem. Maybe it could help you solve yours as well. Cheers! Commented Oct 17, 2015 at 1:51
  • Got Solution at: stackoverflow.com/questions/33117540/… Commented Oct 21, 2015 at 5:55

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.