0

I am using firebase and have an Order-URL with some .pdf-files in it. Here is an image, which shows it: enter image description here

I have this code:

   @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {

    View view = inflater.inflate(R.layout.fragment_wiki, container, false);

    // Inflate the layout for this fragment
    WebView webView = (WebView) view.findViewById(R.id.webView1);
    webView.getSettings().setJavaScriptEnabled(true);

    //FireBase Connection
    StorageReference mStorageRef;
    mStorageRef = FirebaseStorage.getInstance().getReference();
    mStorageRef.getDownloadUrl();


    String myPdfUrl = "https://firebasestorage.googleapis.com/v0/b/realtime-chat-46f4c.appspot.com/o/documents%2Fbf307aa5-79ae-4532-8128-ee394537b357.pdf?alt=media&token=2d0c5329-4717-4adc-9418-6614913e5bfa";
   /* String url = "http://docs.google.com/gview?embedded=true&url=" + myPdfUrl;
    webView.loadUrl(url);*/

    try {
        myPdfUrl = URLEncoder.encode(myPdfUrl,"UTF-8");
        webView.loadUrl("https://docs.google.com/gview?embedded=true&url=" + myPdfUrl);
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }

    return view;
}

What I want is: - to get all the file-names of the Order-Url in firebase from the link, I show in the image above - Get the url of the download path of each of the file-names in the order

When I just copy the download URL, I can easy add it in code and load the file. But I want it dynamically, means, always, when I add an file in this storage in firebase, it should be detected and added/removed, and so on.

I dont want to change my code all the time, just to add the new download-url of the files.

Does anybody have experience, or idea how to solve it?

Thanks a lot

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
  • There is no API in the Firebase SDK to get a listing of files from Storage. See https://stackoverflow.com/questions/37335102/how-to-get-a-list-of-all-files-in-cloud-storage-in-a-firebase-app – Frank van Puffelen Apr 15 '18 at 22:24

1 Answers1

1

Your use case sounds like a great opportunity to use Firebase's Cloud Functions, particularly the Cloud Storage triggers part.

The basic idea is that you can write code which will be triggered whenever some event happens. In your case, the event is when files are uploaded to your "Order-Url" and you just need to write some code that will make a record of the download URLs for these files.

That approach is very much "ahead-of-time". As an alternative, you could use the Google Storage SDK or APIs to query the underlying storage bucket and folder that Firebase Storage uses for your files.

Tom Bailey
  • 682
  • 5
  • 12
  • Thank you Tom, I will take a look to the "alternative", because I want to upload the files direct on browser, where the firebase-project is, and just updating code, depending on the bucket of this. – New GenerationFashion Apr 15 '18 at 17:20