MarquisLP / World-Scribe

An Android app for fictional world-building
MIT License
41 stars 7 forks source link

Some users are unable to upload to Dropbox #10

Closed MarquisLP closed 6 years ago

MarquisLP commented 6 years ago

Several users have reported issues with being unable to upload to Dropbox. These issues don't seem to be affecting every device model and Android version, but so far, there doesn't seem to be any correlation between affected devices. The following device+Android version combos are currently known to experience these issues:

Based on user reports, this issue has been occurring very sporadically since at least 3 May 2017.

MarquisLP commented 6 years ago

It's possible that this issue isn't dependent on device, but rather on upload size. Admittedly, I haven't tested uploading with a very large World, so we may have to cover that use-case sometime in the near future. Also, when questioning users who report this bug, it would be pertinent to also ask them roughly how big their Worlds are (number of Articles, amount of text, etc.).

If upload size does turn out to be the cause, it might be worth looking into this implementation of Dropbox uploading: https://github.com/dropbox/dropbox-sdk-java/blob/master/examples/upload-file/src/main/java/com/dropbox/core/examples/upload_file/Main.java#L68

MarquisLP commented 6 years ago

Actually, here's a good way to confirm that this issue is, indeed, purely device-related: when a user reports this issue happening to them, ask them to send the entire World folder that they're trying to upload.

Then I can try uploading the World folder to Dropbox on my own device. If it succeeds, then we know it's a device/environment problem. Otherwise, it's probably an issue with upload size as noted above.

MarquisLP commented 6 years ago

I've determined the cause of the issue, as well as a fix.

All of the error logs we've been sent have this same line: {".tag":"malformed_path","malformed_path":null},"upload_session_id":"AAAAAAAAADBkZ6gmp-AxCQ"}

The 'null' path is the issue here: somewhere in the code, we were telling Dropbox to upload a non-existent file path. So I looked at UploadToDropboxTask.uploadRecursive() and found this problematic piece of code:

private void uploadRecursive(File originalFile) throws DbxException, IOException {
    if (file.exists()) {
    File[] files = originalFile.listFiles();
    // ...
        if (file.isDirectory()) {

The problem? If originalFile is not a directory, then originalFile.listFiles() returns null, according to the official docs.

So to fix this issue, we have to restructure this method so that the isDirectory() check happens before listFiles().