0

I still don't have much experience in coding so sorry for my ignorance.

I am looking to upload multiple images files to Firebase Storage and wait for it one by one to complete before uploading the next file.

Here is how I am trying to do it using recursive function...

private void uploadProperties(final StorageReference ref, final ArrayList<Uri> images, final int index,
                              final UploadingListener uploadingListener, final String URL)
{
    final StorageReference tempRef=ref.child(Integer.toString(index));
    tempRef.putFile(images.get(index)).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
        @Override
        public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
            String divide="~~";
            if (index==0)
            {
                divide="";
            }
            if (index!=images.size()-1)
            {
                uploadProperties(ref,images,index+1,uploadingListener,URL+divide+taskSnapshot.getDownloadUrl().toString());
            }
            else
            {
                uploadingListener.OnComplete(Status.SUCCESS, URL+divide + taskSnapshot.getDownloadUrl().toString());
            }
        }
    }).addOnFailureListener(new OnFailureListener() {
        @Override
        public void onFailure(@NonNull Exception e) {
            uploadingListener.OnComplete(Status.FAILED,"");
        }
    });
}

And to to use it... propertiesImagestoRef is the storage reference to the correct path. Images is an Arraylist of images to upload.

uploadProperties(propertiesImagesStorRef, images, 0, new UploadingListener() {
        @Override
        public void OnComplete(Status status, String URLs) {//coding here to split the URLs and do all after upload complete stuffs},"");

But I am getting this error.

java.lang.SecurityException: Permission Denial: reading com.android.providers.media.MediaDocumentsProvider uri content://com.android.providers.media.documents/document/image%3A40 from pid=3040, uid=10058 requires android.permission.MANAGE_DOCUMENTS, or grantUriPermission()

In my AndroidManifest.xml I already added

    <uses-permission android:name="android.permission.MANAGE_DOCUMENTS"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>

It works fine for single file but not for multiple files. So what am I doing wrong or is there any other way to do multiple files upload?

0 Answers0