#[Bug] Android SDK Storage would not upload files larger than 5 MB if the fileID is not unique

32 messages · Page 1 of 1 (latest)

sour herald
#

I am using the Android SDK version 2.0.0.

Using this modified code snippet from the docs:

String bucketID = "bucketID";
String fileID = "fileID";
File file;
Object upload = storage.createFile(
                  bucketID,
                  fileID,
                  InputFile.Companion.fromFile(file),
                  new Continuation<Object>() {
                      @NotNull
                      @Override
                      public CoroutineContext getContext() {
                          return EmptyCoroutineContext.INSTANCE;
                      }
      
                      @Override
                      public void resumeWith(@NotNull Object o) {
                          String json = "";
                          try {
                              if (o instanceof Result.Failure) {
                                  Result.Failure failure = (Result.Failure) o;
                                  throw failure.exception;
                              } else if (o instanceof io.appwrite.models.File){
                                  io.appwrite.models.File response = (io.appwrite.models.File) o;
                                  if (response.getChunksUploaded() == response.getChunksTotal()){
                                      Log.d("File Upload", "Finish Uploading " + response.getName());
                                  }
                              } else {
                                  Log.d("File Upload", "Unexpected result type");
                              }
                          } catch (Throwable th) {
                              Log.e("ERROR", th.toString());
                              th.printStackTrace();
                          }
                      }
                  }
          )

Note that fileID is using a string and not using unique ID retrieved from ID.Companion.unique().

(cont...)

#

If the file is larger than 5 MB and fileID is not using ID.Companion.unique(), Appwrite will throw an exception that the file cannot be found:

io.appwrite.exceptions.AppwriteException: The requested file could not be found.
    at io.appwrite.Client$awaitResponse$2$1.onResponse(Client.kt:490)
    at okhttp3.internal.connection.RealCall$AsyncCall.run(RealCall.kt:519)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1137)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:637)
    at java.lang.Thread.run(Thread.java:1012)

However the application has proper permissions and able to read and write the file. This does not happen if the fileID is using a unique ID retrieved from ID.Companion.unique(). This also does not happen on files smaller than 5 MB.

#

I'm sorry, I just realized that the Android SDK itself has a github page. Should I post an issue over there instead?

vivid epoch
#

Also, is there an active session?

sour herald
# vivid epoch Also, is there an active session?

There is an active session, yes. If I loop this code snippet to iterate over files with various sizes, the smaller ones will be uploaded while the ones bigger than 5 MB will result in the SDK throwing the exception above.

sour herald
vivid epoch
#

What are the permissions on the bucket and files?

sour herald
#

Create files only for any user.

sour herald
sour herald
vivid epoch
sour herald
#

Some additional note: the fileID itself isn't the same for every file actually, but rather it was generated from timestamp in my system. I just put a variable in the code snippet to make it simpler

sour herald
#

It's not my intention to put files with the same ID in the server though

#

I wanted to generate the fileID string from the timestamp when the file was created

#

However whenever I insert any strings other than ID.Companion.unique() on any file larger than 5 MB, this happens.

vivid epoch
#

You said there was some loop uploading multiple files...but each file id you're generating is unique and doesn't exist on the server yet, right?

sour herald
#

Yes

#

This appears to be more of an issue to the Android SDK itself rather than the server though

vivid epoch
# sour herald Yes

So what are the permissions on the collection and file that gets generated?

sour herald
#

permissions are what I have expected to, yes.

#

Bucket: any users can create

vivid epoch
sour herald
#

2.0.0

vivid epoch
sour herald
#

yes

#

only create

vivid epoch
sour herald
#

I apologize but I will have to do it later. It's already 5 am here and I have not slept.

vivid epoch
#

Also, make sure you're using https for the endpoint.