Results 1 to 5 of 5

Thread: File-Upload for files that are in a store

  1. #1
    Sencha User
    Join Date
    Oct 2016
    Posts
    4

    Default File-Upload for files that are in a store

    Hey together,

    I'm new at JS and ExtJS so please forgive if I'm completely wrong.

    I have a grid where i can drop files. Those files are stored:

    Code:
        drop : function(e) {
            e.stopEvent();
    
            Ext.Array.forEach(Ext.Array.from(e.browserEvent.dataTransfer.files),
                    function(file) {
    
                        var store = Ext.getStore('Files');
    
                        store.add({
                            file : file,
                            name : file.name,
                            size : file.size
                        });
                    });
    
        },
    Now,.. If I click on a Button, every single file in the store should be uploaded:

    Code:
            store.each(function (record) {
                var formData = new FormData();
                formData.append("file", record.data.file);
    
                Ext.Ajax.request({
                    url: 'http://localhost:8080/upload/' + record.data.name,
                    method: 'POST',
                    data: formData,
                    isUpload: true,
                    async: false,
                    success: function(response) {
                        console.log(response.responseText);
                    },
                    failure: function(response, opts) {
                        console.log('failed');
                    }
                });
    But this doesn't work since the FormData is not applied to the request. Do you have any idea to solve this?

  2. #2
    Sencha User
    Join Date
    Feb 2013
    Location
    California
    Posts
    11,985
    Answers
    506

    Default

    Is the formData variable getting populated correctly before the request attempt? And so the server is receiving the request but the data is empty?

  3. #3
    Sencha User
    Join Date
    Oct 2016
    Posts
    4

    Default

    Thanks for your reply.

    After I append the file, I checked the FormData to make sure that the file is there:

    Code:
                for (var pair of formData.entries()) {
                    console.log(pair[0]+ ', ' + pair[1]);
                }
    Output:
    Code:
    file, [object File]
    I checked the request on server side (jersey): seems like nothing is there.

    After that i checked the documentation of Axt.Ajax and the valid parameters for request():
    http://docs.sencha.com/ext/6.0.2-cla...method-request

    Looks like there is no "data" parameter, right?

  4. #4
    Sencha User
    Join Date
    Feb 2013
    Location
    California
    Posts
    11,985
    Answers
    506

    Default

    I'm not seeing one in the docs. I've not tried to implement a file upload this way myself. Not sure if you've seen user extensions for multiple file uploads such as this:
    https://github.com/ivan-novakov/extjs-upload-widget

    I've not tested it in Ext JS 6, but I expect that it will work or at least serve as a guide for your own implementation.

  5. #5
    Sencha User
    Join Date
    Oct 2016
    Posts
    4

    Default

    Quote Originally Posted by Gary Schlosberg View Post
    I've not tried to implement a file upload this way myself.
    Do you have any other idea how I could implement something like this?

    Quote Originally Posted by Gary Schlosberg View Post
    Not sure if you've seen user extensions for multiple file uploads such as this:
    https://github.com/ivan-novakov/extjs-upload-widget
    Thanks. I will have a look on this. Just thought there would be an easy way.

  6. #6
    Sencha User
    Join Date
    Feb 2013
    Location
    California
    Posts
    11,985
    Answers
    506

    Default

    Uploading multiple files at once is not supported by the framework, but there have been many user implementations. Hopefully that one works for you.

Similar Threads

  1. Upload Multiple Files/More than One File at Once
    By tljuenem in forum Ext: Discussion
    Replies: 3
    Last Post: 23 Aug 2013, 10:04 AM
  2. Filter Files with File Upload Field
    By cyk in forum Ext 2.x: Help & Discussion
    Replies: 5
    Last Post: 1 Mar 2009, 9:32 PM
  3. File Upload dropping files
    By astout in forum Ext 2.x: Help & Discussion
    Replies: 0
    Last Post: 12 Jan 2009, 4:31 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •