jQuery file upload: cannot upload file in Safari 11
Asked Answered
E

2

5

Steps to reproduce the bug in Safari 11:

  1. Create a folder with Cyrillic letters in the title, for example "русский_язык"
  2. Add some files to the folder
  3. Open https://blueimp.github.io/jQuery-File-Upload/ in Safari 11.1 browser
  4. Upload file from that folder

Actual result: file was not uploaded.

For a better understanding, watch the video for Safari 11: https://drive.google.com/open?id=16tU8iBn0U9bUs7u5pM4ZBXmxpfJIv8WV

Try to upload the same file but use Safari 10.

Actual result: all is good, file was uploaded without any problems.

For a better understanding, watch the video for Safari 10: https://drive.google.com/open?id=1IO--Y1RjETAYAucaNyqhM6HZcQdNKDkI

Update 28.05.2018 After a few hours of debagging via crossbrowsertesting.com (because I do not have safari) I found temporary solution: on this line https://github.com/blueimp/jQuery-File-Upload/blob/master/js/jquery.fileupload.js#L1182 need to replace

entries = fileInput.prop('webkitEntries') ||  fileInput.prop('entries')

to

entries = []

And everything should works.

I guess it happened becasuse apple added to safari experimental feature - FileSystemEntry. More info about this feature https://developer.mozilla.org/en-US/docs/Web/API/FileSystemEntry.

If entries variable will be empty jquery.fileupload.js will use well-tried files attribute for getting uploaded files. Look to code https://github.com/blueimp/jQuery-File-Upload/blob/master/js/jquery.fileupload.js#L1189 for more details

Also I report a bug to Safari and to Sebastian Tschan (author of this library)

Ewart answered 19/4, 2018 at 10:6 Comment(8)
I don't think report a bug here helpsIndoiranian
@CarstenLøvboAndersen, maybe. but "Issue" section is closed in repo github.com/blueimp/jQuery-File-UploadEwart
Solution u've adviced here is not working for me :( Is there any news about fixing this issue?Rann
@Dmitry, it should works. What exactly you do and what not working?Ewart
@VladimirKalyuzhny Hello, i've done this joxi.ru/RmzqpEYC0qpGqr , but still can't upload file in Safari 11 from Russian-letters folderRann
@VladimirKalyuzhny I've rechecked site and clear the cache and looks like your solution now works. Thanks! : )Rann
@Dmitry, I`am glad to hear itEwart
PR opened - github.com/blueimp/jQuery-File-Upload/pull/3512 - let's solve it together.Dockage
H
7

I found the same problem now. I have already detected that the code snippet: jquery.fileupload.js

_handleFileTreeEntry: function (entry, path) {
        var that = this,
            dfd = $.Deferred(),
            errorHandler = function (e) {
                if (e && !e.entry) {
                    e.entry = entry;
                }
                // Since $.when returns immediately if one
                // Deferred is rejected, we use resolve instead.
                // This allows valid files and invalid items
                // to be returned together in one set:
                dfd.resolve([e]);
            },
            successHandler = function (entries) {
                that._handleFileTreeEntries(
                    entries,
                    path + entry.name + '/'
                ).done(function (files) {
                    dfd.resolve(files);
                }).fail(errorHandler);
            },
            readEntries = function () {
                dirReader.readEntries(function (results) {
                    if (!results.length) {
                        successHandler(entries);
                    } else {
                        entries = entries.concat(results);
                        readEntries();
                    }
                }, errorHandler);
            },
            dirReader, entries = [];
        path = path || '';
        if (entry.isFile) {
            if (entry._file) {
                // Workaround for Chrome bug #149735
                entry._file.relativePath = path;
                dfd.resolve(entry._file);
            } else {
                entry.file(function (file) {  // <=== here
                    file.relativePath = path;
                    dfd.resolve(file);
                }, errorHandler);
            }
        } else if (entry.isDirectory) {
            dirReader = entry.createReader();
            readEntries();
        } else {
            // Return an empy list for file system items
            // other than files or directories:
            dfd.resolve([]);
        }
        return dfd.promise();

}

in this function, when the code run into the condition

            entry.file(function (file) {
                file.relativePath = path;
                dfd.resolve(file);
            }, errorHandler);

Safari is return the errorHandler for the file function callback. the function api reference here: https://developer.mozilla.org/en-US/docs/Web/API/FileSystemFileEntry/file.

It must be Safari 11's bug. After soon I will report the bug for Apple. In jQuery.fileupload.js, I guess the better fixed method is detect the UserAgent with Safari 11. But I think Apple should fix this problem.

Hudnall answered 27/4, 2018 at 9:26 Comment(4)
The funny thing is that the same behavior but the target is the desktop folder, it totally works. it sucks me!Hudnall
Stevenhong, I've updated my post. Added my temprorary solution how to fix this bugEwart
I report the bug to Apple with bugreport.apple.com/web/?problemID=39969255Hudnall
It seems that Safari Preview version has new release to download. Maybe you can try. but the OS need MacOS High Sierra. You see: developer.apple.com/safari/downloadHudnall
A
0

I reproduced same bug with a folder name contains Japanese characters, and caught NotFoundError: Path does not exist here same as @Stevenhong's answer (macOS 10.13.4 and Safari 11.1).

I succeeded in uploading same files when I use Safari Technology Preview Release 58!

Awry answered 11/6, 2018 at 11:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.