Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Runtime error when using getFileStack #1413

Closed
BodoHuber opened this issue May 21, 2019 · 7 comments
Closed

Runtime error when using getFileStack #1413

BodoHuber opened this issue May 21, 2019 · 7 comments

Comments

@BodoHuber
Copy link

BodoHuber commented May 21, 2019

After updating form V4.5.3 I get runtime errors in my code when trying to use the function getFileStack.

I am under the impression that both functions 'getFileStack' and 'getFileList' are not fileManager aware and do not continue to work. They are the only functions I found which try to access 'this.files' which seems to be replaced by the fileManager. Accessing the missing 'this.files' causes my runtime error at least.

Please double check the compatibility of these two functions with the new and fancy fileManager.

@kartik-v
Copy link
Owner

Can you share your plugin configuration and what you are trying to achieve?

@BodoHuber
Copy link
Author

Here is my configuration. I am trying to get lastModified and size information from the file stack because I want to save that information in addition.

        $("#input-salaryfiles").fileinput({
            uploadUrl: yii.salariesUpdate.getUploadUrl,
            uploadAsync: true,
            showUploadedThumbs: false,
            maxFileCount: 5,
            maxFileSize: 2800,
            language: language.substring(0,2),
            uploadExtraData: function (previewId, index) {
                var files = $("#input-salaryfiles").fileinput('getFileStack');
                var obj = {};
                for (i = 0; i < files.length; ++i) {
                   var strProperty = 'fileproperties[' + i + '][lastModifiedTimestamp]';
                   obj[strProperty] = files[i].lastModified;
                   strProperty = 'fileproperties[' + i + '][size]';
                   obj[strProperty] = files[i].size;
                }
            return obj;
            }
        }

Runtime error is caused by the function getFileStack because of accessing undefined this.file property:

fileinput.js:4707 Uncaught TypeError: Cannot read property 'stack' of undefined
at FileInput.getFileStack (fileinput.js:4707)
at HTMLInputElement. (fileinput.js:5291)
at Function.each (jquery.js:354)
at jQuery.fn.init.each (jquery.js:189)
at jQuery.fn.init.$.fn.fileinput (fileinput.js:5274)
at FileInput.uploadExtraData (salaries-update.js:37)
at FileInput._getExtraData (fileinput.js:2929)
at FileInput._ajaxSubmit (fileinput.js:3001)
at FileInput._uploadSingle (fileinput.js:3321)
at Object. (fileinput.js:5199)

@kartik-v
Copy link
Owner

kartik-v commented May 22, 2019

Check if this fix resolves your issue. Use getFileList to get an array of file objects. Use getFileStack to get an object/associative array of file objects indexed by file identifier.

@kartik-v kartik-v added this to the 5.x milestone May 22, 2019
@BodoHuber
Copy link
Author

Runtime error is gone, but contrary to the documentation it does not return an array any longer. It returns an object now which is a bit harder to consume.

@BodoHuber
Copy link
Author

Ok, I made my code work again. Thanks for the quick fix.

Maybe you want to change the documentation to tell it returns an object now? Or you want to continue to fix it to return an array again. This should be an associative one indexed by the fileId value which is part of the Ajax dataset. Makes it most easy to use.

@kartik-v
Copy link
Owner

Thanks. The docs are updated.

Note that if you need an array of file objects - use the getFileList method. The getFileStack method will return an object (associative array) of file objects indexed by file identifier.

@BodoHuber
Copy link
Author

getFileStack works like a charm with your $.each sample in the docs. Well done.

Also thanks for the new getFileList section in the docs which explains that all the constraints for the result are the same as for getFileStack (validation errors, already uploaded). This was indeed not clear to me before.

Anyhow, I will continue using the object result of getFileStack just because of the "never change a running system" reason.

Again thanks for your great work, man.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants