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);
                      }
                });
            });
        });
Dhana
  • 711
  • 3
  • 14
  • 40
  • I used your example as a solution to another [problem](http://stackoverflow.com/questions/33117540/how-to-upload-and-display-file-using-play-framework-and-jquery/33181675#33181675). Maybe it could help you solve yours as well. Cheers! – Chrizt0f Oct 17 '15 at 01:51
  • Got Solution at: http://stackoverflow.com/questions/33117540/how-to-upload-and-display-file-using-play-framework-and-jquery/33181675?noredirect=1#comment54281573_33181675 – Dhana Oct 21 '15 at 05:55

0 Answers0