Firebase SignedURL not equal to loading url storage

I already asked a question to get downloadURL from Firebase Storage, the answer I was given was:

bucket.file(filename).getSignedUrl({
  action: 'read',
  expires: '03-17-2025'
}, function(err, url) {
  if (err) {
    console.error(err);
    return;
  }

  // The file is now available to read from this URL.
  request(url, function(err, resp) {
    // resp.statusCode = 200
  });
});

      

The one given by the previous code does not work when I use it to load an image with Glide or rework audio or video files with ExoPlayer.

However, I am getting a completely different URL than the one given by the Firebase store (which works for Glide and ExoPlayer) when I upload a file that looks like this:

https://firebasestorage.googleapis.com/v0/b/project-PROYECT_NUMBER.appspot.com/o/Messages%2Fimages%2F-KUj4wvXXl6aj9XXXX%2F1493147111111?alt=media&token=TOKEN

How can I get the correct downloadUrl like the one I would get using the Android or iOS SDK on the server side?

+3


source to share


3 answers


There is no way to get the server side download url like you can using Android, iOS or Javascript SDK. You have to generate the url by calling getSignedUrl ().

You might want to check if you have permission to read the file at the specified URL.

By default, you need to authenticate.



Check storage rules in firebase console

https://firebase.google.com/docs/storage/security/#authorization

+2


source


I hope you download the image via the app only na? After downloading it, you will get back the download link. Hope this helps you.



import com.google.firebase.storage.StorageTask;

 final StorageTask uploadTask = uplodedFileRef.putBytes(data);
    Log.d(TAG, "uploadFilefromPath: " + uplodedFileRef.getPath().toString());
uploadTask.addOnFailureListener(new OnFailureListener() {
                @Override
                public void onFailure(@NonNull Exception exception) {
                    // Handle unsuccessful uploads
                    Toast.makeText(acty, "Upload Failed", Toast.LENGTH_SHORT).show();
                    dialog.dismiss();
                    sendResult(false, Uri.EMPTY);
                }
            })
            .addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
                @Override
                public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
                    // taskSnapshot.getMetadata() contains file metadata such as size, content-type, and download URL.
                    Toast.makeText(acty, "Upload Successful", Toast.LENGTH_SHORT).show();
                    dialog.dismiss();
                    sendResult(true, taskSnapshot.getDownloadUrl());
                }
            })
            .addOnProgressListener(new OnProgressListener<UploadTask.TaskSnapshot>() {
                @Override
                public void onProgress(UploadTask.TaskSnapshot taskSnapshot) {

                    int bytesTransferred = (int) taskSnapshot.getBytesTransferred();
                    int totalBytes = (int) taskSnapshot.getTotalByteCount();
                    int progress = (100 * bytesTransferred) / totalBytes;

                    Log.v(TAG, "Bytes transferred: " + taskSnapshot.getBytesTransferred());
                    Log.v(TAG, "TotalBytes: " + totalBytes);
                    Log.v(TAG, "Upload is: " + progress + "% done");

                    dialog.setContent("Upload in Progress");
                    dialog.getProgressBar().setIndeterminate(false);
                    // double progress = (100.0 * taskSnapshot.getBytesTransferred()) / taskSnapshot.getTotalByteCount();
                    dialog.getProgressBar().setMax(totalBytes / 1024);
                    dialog.setMaxProgress(totalBytes / 1024);
                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
                        dialog.getProgressBar().setProgress(bytesTransferred / 1024, true);
                        dialog.setProgress(bytesTransferred / 1024);
                    } else
                        dialog.getProgressBar().setProgress(bytesTransferred / 1024);
                    dialog.setProgress(bytesTransferred / 1024);
                    // dialog.getProgressBar().setProgress((int) progress);
                }
            });

      

+1


source


addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
      @Override
      public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) { //success
            sendResult(true, taskSnapshot.getDownloadUrl());
      }
})

      

in this taskSnapshot.getDownloadUrl()

you will get the download url then store it in firebase database which you can get when

+1


source







All Articles