Search code examples
jqueryasp.net-mvcjquery-file-upload

Send path route via ajax call (using fleupload jquery plugin)


What I am trying to accomplish is the following. I want to be able to send a file path (such as "~/MyFolder/MySubFolder") through Ajax to a MVC 4 controller. The problem I'm facing is that, I'm using the fileupload jquery plugin and this does not give me direct control over what I send over to the server (meaning, it sends the file with a couple of attributes but I can't add extra attributes to it).

I was trying to send the path as an html attribute to the ajax call:

url: "/api/upload" + path

but for obvious reasons this doesn't work. Any help would be appreciated! Thank you


Solution

  • If i am right you are using this plugin BluImp

    1: https://github.com/blueimp/jQuery-File-Upload for file upload and sending additional data is supported is available in this try like this :

    <form id="fileupload" action="server/php/" method="POST" enctype="multipart/form-data">
        <input type="hidden" name="example1" value="test">
        <div class="row">
            <label>Example: <input type="text" name="example2"></label>
        </div>
        <!-- ... -->
    </form>
    

    By default, the plugin calls jQuery's serializeArray method on the upload form to gather additional form data for all input fields (including hidden fields). The value of these form fields will be sent to the server along with the selected files.

    Note: If you set the formData option, these fields won't be sent to the server, since the formData object will override them. You can however create a formData object of the form fields manually using jQuery's serializeArray method method:

    For more info : Plugin wiki