0

I am using jQuery file upload plugin to upload my files.

My code is:

$('#image').fileupload({
    singleFileUploads : true,
    acceptFileTypes : /(\.|\/)(gif|jpe?g|png)$/i,
    autoUpload : false,
    maxFileSize : 1000000,
});

When I set autoupload to true, its working as expected. But when I set it to false and I want to upload file manually with submit button, it is not working and the image field has no image attached.

I have used the following JavaScript:

<script src="/scripts/fileUpload/jquery.ui.widget.js"></script>
<script src="/scripts/fileUpload/jquery.iframe-transport.js"></script>
<script src="/scripts/fileUpload/jquery.fileupload.js"></script>
<script src="/scripts/fileUpload/jquery.fileupload-ui.js"></script>
<script src="/scripts/fileUpload/jquery.fileupload-process.js"></script>
<script src="/scripts/fileUpload/jquery.fileupload-validate.js"></script>

Can any one kindly tell me what's wrong here?

1 Answer 1

1

To upload your file when you click on a button:

$('input').fileupload({
    autoUpload: false,
    add: function (e, data) {
        $("button").click(function () {
            $("p").html("Requête envoyée");
            data.submit();
        })
    },
    done: function (e, data) {
        $("p").append("Upload terminé");
    },
});

With following HTML :

<input type="file" data-url="/echo/json" />
<button>Download</button>
<p></p>

Tested on Chrome 31, IE11 and Firefox 25 : http://jsfiddle.net/Fractaliste/MEA58/1/

Sign up to request clarification or add additional context in comments.

3 Comments

i have already tried this, this is working in chrome but not working in firefox.
@Shahzeb I've add some changes and test. It should work on Firefox.
@Fractaliste can you please take a look at my question stackoverflow.com/questions/29386928/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.