-
-
Notifications
You must be signed in to change notification settings - Fork 7.8k
Upload fails on iOS 12 on iPhone 6/7/8 #3536
Description
This is an odd issue we observed in our project, that is very specific. It only occurs in the iPhone simulator for 6, 7 and 8, with iOS 12. Other phones on iOS 12 works fine, and 6/7/8 phones with iOS 11 and 13 works too. We have a ReactNative app with a WebView; and it also seemed that it worked with the "old" WebView, but not the newer WkWebView. At the moment I am not sure if the problem existed in Safari or not, but I think so. But, I don't think this matters too much for the question.
The failure is that after the user has selected a file for upload, nothing happens (no attempt at uploading the file in the background). Since it is on an iPhone in an embedded web app, it is fairly hard to debug.
Anyway, we sort-of identified the problem, and a potential fix, but the "offending" code is pretty complicated, so it is hard to see what's really going on, and what side-effects a fix could result in.
The culprit in this specific case is that _handleFileTreeEntry() returns/resolves a single (file) object, where the caller expects an array.
It begins (or ends here):
_onAdd(null, data); // data.files is supposed to be an array in this function
However, that data.files is set in add() from a Promise that bubbles down from this chain:
_getFileInputFiles -> _getSingleFileInputFiles -> _handleFileTreeEntries -> _handleFileTreeEntry
In _handleFileTreeEntry(), we have this code:
if (entry.isFile) {
if (entry._file) {
// Workaround for Chrome bug #149735
entry._file.relativePath = path;
dfd.resolve(entry._file); // <-- this may also be a problem
} else {
entry.file(function(file) {
file.relativePath = path;
dfd.resolve(file); // <--- THIS IS OUR PROBLEM
}, errorHandler);
}
} else if (entry.isDirectory) {Here, on the marked lines, it resolves to a single file, while in other parts of the function it resolves to a list of files. When we change the marked line to dfd.resolve( [ file ] ) it works in our test case.
So, does anyone know why this inconsistency exists, and what would break if one fixes it?