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...)