How to get offline uploded file Download url in Firebase












0















I want to get Download Url from uploadTask.addOnProgressListener method of Firebae. How I can get Download Url using following code?



    UploadTask uploadTask = storageRef.putBytes(data);

uploadTask.addOnProgressListener(new OnProgressListener<UploadTask.TaskSnapshot>()
{
@Override
public void onProgress(UploadTask.TaskSnapshot taskSnapshot)
{
Log.d("aaaaasessin",""+taskSnapshot.getTask().getResult());
}
});


I used taskSnapshot.getTask().getResult() but not working. Pease Help me.










share|improve this question





























    0















    I want to get Download Url from uploadTask.addOnProgressListener method of Firebae. How I can get Download Url using following code?



        UploadTask uploadTask = storageRef.putBytes(data);

    uploadTask.addOnProgressListener(new OnProgressListener<UploadTask.TaskSnapshot>()
    {
    @Override
    public void onProgress(UploadTask.TaskSnapshot taskSnapshot)
    {
    Log.d("aaaaasessin",""+taskSnapshot.getTask().getResult());
    }
    });


    I used taskSnapshot.getTask().getResult() but not working. Pease Help me.










    share|improve this question



























      0












      0








      0








      I want to get Download Url from uploadTask.addOnProgressListener method of Firebae. How I can get Download Url using following code?



          UploadTask uploadTask = storageRef.putBytes(data);

      uploadTask.addOnProgressListener(new OnProgressListener<UploadTask.TaskSnapshot>()
      {
      @Override
      public void onProgress(UploadTask.TaskSnapshot taskSnapshot)
      {
      Log.d("aaaaasessin",""+taskSnapshot.getTask().getResult());
      }
      });


      I used taskSnapshot.getTask().getResult() but not working. Pease Help me.










      share|improve this question
















      I want to get Download Url from uploadTask.addOnProgressListener method of Firebae. How I can get Download Url using following code?



          UploadTask uploadTask = storageRef.putBytes(data);

      uploadTask.addOnProgressListener(new OnProgressListener<UploadTask.TaskSnapshot>()
      {
      @Override
      public void onProgress(UploadTask.TaskSnapshot taskSnapshot)
      {
      Log.d("aaaaasessin",""+taskSnapshot.getTask().getResult());
      }
      });


      I used taskSnapshot.getTask().getResult() but not working. Pease Help me.







      java android firebase firebase-storage






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 14 '18 at 12:51









      Alex Mamo

      42.6k82860




      42.6k82860










      asked Nov 14 '18 at 12:09









      ajay dhadhalajay dhadhal

      10610




      10610
























          1 Answer
          1






          active

          oldest

          votes


















          1














          In order to get the download url, you need to use addOnSuccessListener, like in the following lines of code:



          uploadTask.addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
          @Override
          public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
          storageRef.getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>() {
          @Override
          public void onSuccess(Uri uri) {
          String url = uri.toString();

          //Do what you need to do with url
          }
          });
          }
          });


          As in the Firebase release notes on May 23, 2018 is mentioned that:




          Cloud Storage version 16.0.1



          Removed the deprecated StorageMetadata.getDownloadUrl() and UploadTask.TaskSnapshot.getDownloadUrl() methods. To get a current download URL, use StorageReference.getDownloadUr().




          So now when calling getDownloadUrl() on a StorageReference object it returns a Task object and not an Uri object anymore.



          Please also rememeber, neither the success listener nor the failure listener (if you intend to use it), will be called if your device cannot reach Firebase Storage backend. The success/failure listeners will only be called once the data is committed to, or rejected by the Firebase servers.






          share|improve this answer


























          • @FrankvanPuffelen Oh sorry, my bad. Answer updated. Thanks again!

            – Alex Mamo
            Nov 14 '18 at 14:29











          • Thanks for your answer but,I perform upload task offline so i can't use onSuccsess().I have to use only uploadTask.addOnProgressListener()

            – ajay dhadhal
            Nov 15 '18 at 5:07













          • Yes, that's correct, onSuccsess() is not triggered while offile but unfortunately using addOnSuccessListener you cannot override onSuccess() method to get the download url. Which makes sense because you can only get the download url only once you get a responde from the server (onSuccess is triggered). You cannot get a download url as long as the task is not completed, right?

            – Alex Mamo
            Nov 15 '18 at 7:18











          • OK,any alternative way avilable if so please suggest me

            – ajay dhadhal
            Nov 15 '18 at 7:25











          • No, there is not. You can get the download url only when the upload is successful, with other words when the server provides you the url. When you are offline and there is no direct connection between the device and to the server, there is no url that you can get. Can I help you with other informations?

            – Alex Mamo
            Nov 15 '18 at 7:28













          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53299915%2fhow-to-get-offline-uploded-file-download-url-in-firebase%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1














          In order to get the download url, you need to use addOnSuccessListener, like in the following lines of code:



          uploadTask.addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
          @Override
          public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
          storageRef.getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>() {
          @Override
          public void onSuccess(Uri uri) {
          String url = uri.toString();

          //Do what you need to do with url
          }
          });
          }
          });


          As in the Firebase release notes on May 23, 2018 is mentioned that:




          Cloud Storage version 16.0.1



          Removed the deprecated StorageMetadata.getDownloadUrl() and UploadTask.TaskSnapshot.getDownloadUrl() methods. To get a current download URL, use StorageReference.getDownloadUr().




          So now when calling getDownloadUrl() on a StorageReference object it returns a Task object and not an Uri object anymore.



          Please also rememeber, neither the success listener nor the failure listener (if you intend to use it), will be called if your device cannot reach Firebase Storage backend. The success/failure listeners will only be called once the data is committed to, or rejected by the Firebase servers.






          share|improve this answer


























          • @FrankvanPuffelen Oh sorry, my bad. Answer updated. Thanks again!

            – Alex Mamo
            Nov 14 '18 at 14:29











          • Thanks for your answer but,I perform upload task offline so i can't use onSuccsess().I have to use only uploadTask.addOnProgressListener()

            – ajay dhadhal
            Nov 15 '18 at 5:07













          • Yes, that's correct, onSuccsess() is not triggered while offile but unfortunately using addOnSuccessListener you cannot override onSuccess() method to get the download url. Which makes sense because you can only get the download url only once you get a responde from the server (onSuccess is triggered). You cannot get a download url as long as the task is not completed, right?

            – Alex Mamo
            Nov 15 '18 at 7:18











          • OK,any alternative way avilable if so please suggest me

            – ajay dhadhal
            Nov 15 '18 at 7:25











          • No, there is not. You can get the download url only when the upload is successful, with other words when the server provides you the url. When you are offline and there is no direct connection between the device and to the server, there is no url that you can get. Can I help you with other informations?

            – Alex Mamo
            Nov 15 '18 at 7:28


















          1














          In order to get the download url, you need to use addOnSuccessListener, like in the following lines of code:



          uploadTask.addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
          @Override
          public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
          storageRef.getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>() {
          @Override
          public void onSuccess(Uri uri) {
          String url = uri.toString();

          //Do what you need to do with url
          }
          });
          }
          });


          As in the Firebase release notes on May 23, 2018 is mentioned that:




          Cloud Storage version 16.0.1



          Removed the deprecated StorageMetadata.getDownloadUrl() and UploadTask.TaskSnapshot.getDownloadUrl() methods. To get a current download URL, use StorageReference.getDownloadUr().




          So now when calling getDownloadUrl() on a StorageReference object it returns a Task object and not an Uri object anymore.



          Please also rememeber, neither the success listener nor the failure listener (if you intend to use it), will be called if your device cannot reach Firebase Storage backend. The success/failure listeners will only be called once the data is committed to, or rejected by the Firebase servers.






          share|improve this answer


























          • @FrankvanPuffelen Oh sorry, my bad. Answer updated. Thanks again!

            – Alex Mamo
            Nov 14 '18 at 14:29











          • Thanks for your answer but,I perform upload task offline so i can't use onSuccsess().I have to use only uploadTask.addOnProgressListener()

            – ajay dhadhal
            Nov 15 '18 at 5:07













          • Yes, that's correct, onSuccsess() is not triggered while offile but unfortunately using addOnSuccessListener you cannot override onSuccess() method to get the download url. Which makes sense because you can only get the download url only once you get a responde from the server (onSuccess is triggered). You cannot get a download url as long as the task is not completed, right?

            – Alex Mamo
            Nov 15 '18 at 7:18











          • OK,any alternative way avilable if so please suggest me

            – ajay dhadhal
            Nov 15 '18 at 7:25











          • No, there is not. You can get the download url only when the upload is successful, with other words when the server provides you the url. When you are offline and there is no direct connection between the device and to the server, there is no url that you can get. Can I help you with other informations?

            – Alex Mamo
            Nov 15 '18 at 7:28
















          1












          1








          1







          In order to get the download url, you need to use addOnSuccessListener, like in the following lines of code:



          uploadTask.addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
          @Override
          public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
          storageRef.getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>() {
          @Override
          public void onSuccess(Uri uri) {
          String url = uri.toString();

          //Do what you need to do with url
          }
          });
          }
          });


          As in the Firebase release notes on May 23, 2018 is mentioned that:




          Cloud Storage version 16.0.1



          Removed the deprecated StorageMetadata.getDownloadUrl() and UploadTask.TaskSnapshot.getDownloadUrl() methods. To get a current download URL, use StorageReference.getDownloadUr().




          So now when calling getDownloadUrl() on a StorageReference object it returns a Task object and not an Uri object anymore.



          Please also rememeber, neither the success listener nor the failure listener (if you intend to use it), will be called if your device cannot reach Firebase Storage backend. The success/failure listeners will only be called once the data is committed to, or rejected by the Firebase servers.






          share|improve this answer















          In order to get the download url, you need to use addOnSuccessListener, like in the following lines of code:



          uploadTask.addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
          @Override
          public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
          storageRef.getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>() {
          @Override
          public void onSuccess(Uri uri) {
          String url = uri.toString();

          //Do what you need to do with url
          }
          });
          }
          });


          As in the Firebase release notes on May 23, 2018 is mentioned that:




          Cloud Storage version 16.0.1



          Removed the deprecated StorageMetadata.getDownloadUrl() and UploadTask.TaskSnapshot.getDownloadUrl() methods. To get a current download URL, use StorageReference.getDownloadUr().




          So now when calling getDownloadUrl() on a StorageReference object it returns a Task object and not an Uri object anymore.



          Please also rememeber, neither the success listener nor the failure listener (if you intend to use it), will be called if your device cannot reach Firebase Storage backend. The success/failure listeners will only be called once the data is committed to, or rejected by the Firebase servers.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 28 '18 at 17:42

























          answered Nov 14 '18 at 12:49









          Alex MamoAlex Mamo

          42.6k82860




          42.6k82860













          • @FrankvanPuffelen Oh sorry, my bad. Answer updated. Thanks again!

            – Alex Mamo
            Nov 14 '18 at 14:29











          • Thanks for your answer but,I perform upload task offline so i can't use onSuccsess().I have to use only uploadTask.addOnProgressListener()

            – ajay dhadhal
            Nov 15 '18 at 5:07













          • Yes, that's correct, onSuccsess() is not triggered while offile but unfortunately using addOnSuccessListener you cannot override onSuccess() method to get the download url. Which makes sense because you can only get the download url only once you get a responde from the server (onSuccess is triggered). You cannot get a download url as long as the task is not completed, right?

            – Alex Mamo
            Nov 15 '18 at 7:18











          • OK,any alternative way avilable if so please suggest me

            – ajay dhadhal
            Nov 15 '18 at 7:25











          • No, there is not. You can get the download url only when the upload is successful, with other words when the server provides you the url. When you are offline and there is no direct connection between the device and to the server, there is no url that you can get. Can I help you with other informations?

            – Alex Mamo
            Nov 15 '18 at 7:28





















          • @FrankvanPuffelen Oh sorry, my bad. Answer updated. Thanks again!

            – Alex Mamo
            Nov 14 '18 at 14:29











          • Thanks for your answer but,I perform upload task offline so i can't use onSuccsess().I have to use only uploadTask.addOnProgressListener()

            – ajay dhadhal
            Nov 15 '18 at 5:07













          • Yes, that's correct, onSuccsess() is not triggered while offile but unfortunately using addOnSuccessListener you cannot override onSuccess() method to get the download url. Which makes sense because you can only get the download url only once you get a responde from the server (onSuccess is triggered). You cannot get a download url as long as the task is not completed, right?

            – Alex Mamo
            Nov 15 '18 at 7:18











          • OK,any alternative way avilable if so please suggest me

            – ajay dhadhal
            Nov 15 '18 at 7:25











          • No, there is not. You can get the download url only when the upload is successful, with other words when the server provides you the url. When you are offline and there is no direct connection between the device and to the server, there is no url that you can get. Can I help you with other informations?

            – Alex Mamo
            Nov 15 '18 at 7:28



















          @FrankvanPuffelen Oh sorry, my bad. Answer updated. Thanks again!

          – Alex Mamo
          Nov 14 '18 at 14:29





          @FrankvanPuffelen Oh sorry, my bad. Answer updated. Thanks again!

          – Alex Mamo
          Nov 14 '18 at 14:29













          Thanks for your answer but,I perform upload task offline so i can't use onSuccsess().I have to use only uploadTask.addOnProgressListener()

          – ajay dhadhal
          Nov 15 '18 at 5:07







          Thanks for your answer but,I perform upload task offline so i can't use onSuccsess().I have to use only uploadTask.addOnProgressListener()

          – ajay dhadhal
          Nov 15 '18 at 5:07















          Yes, that's correct, onSuccsess() is not triggered while offile but unfortunately using addOnSuccessListener you cannot override onSuccess() method to get the download url. Which makes sense because you can only get the download url only once you get a responde from the server (onSuccess is triggered). You cannot get a download url as long as the task is not completed, right?

          – Alex Mamo
          Nov 15 '18 at 7:18





          Yes, that's correct, onSuccsess() is not triggered while offile but unfortunately using addOnSuccessListener you cannot override onSuccess() method to get the download url. Which makes sense because you can only get the download url only once you get a responde from the server (onSuccess is triggered). You cannot get a download url as long as the task is not completed, right?

          – Alex Mamo
          Nov 15 '18 at 7:18













          OK,any alternative way avilable if so please suggest me

          – ajay dhadhal
          Nov 15 '18 at 7:25





          OK,any alternative way avilable if so please suggest me

          – ajay dhadhal
          Nov 15 '18 at 7:25













          No, there is not. You can get the download url only when the upload is successful, with other words when the server provides you the url. When you are offline and there is no direct connection between the device and to the server, there is no url that you can get. Can I help you with other informations?

          – Alex Mamo
          Nov 15 '18 at 7:28







          No, there is not. You can get the download url only when the upload is successful, with other words when the server provides you the url. When you are offline and there is no direct connection between the device and to the server, there is no url that you can get. Can I help you with other informations?

          – Alex Mamo
          Nov 15 '18 at 7:28




















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53299915%2fhow-to-get-offline-uploded-file-download-url-in-firebase%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          這個網誌中的熱門文章

          Academy of Television Arts & Sciences

          L'Équipe

          1995 France bombings