0

I am working on an Angular application using PrimeNG and storing some uploaded image on Firebase Storage service.

In order to upload images I am using this PrimeNG component named FileUpload: https://primefaces.org/primeng/showcase/#/fileupload

Then the images are correctly saved on Firebase Storage service. It works fine. Each time that I drag and drop an image to be uploaded I have something like this:

enter image description here

As you can see in the previous screenshot, eacht time that I drag and drop an image I obtain this uploadedFiles array that contains object having File as type.

What exactly is this File type? Is it a PrimeNG custom type or is it this JS object? (this one: https://developer.mozilla.org/en-US/docs/Web/API/File)

In case how can I retrieve a specific image from Firebase Storage service into one of this File object?

AndreaNobili
  • 40,955
  • 107
  • 324
  • 596
  • 1. Yes, `File` is a native javascript object in browsers. 2. Can you construct a File object? Yes, see here(https://stackoverflow.com/questions/8390855/how-to-instantiate-a-file-object-in-javascript), but in most cases you would never need to do this --- Why do you want to do this? if you tell us what you need to do, we can likely suggest you a much better way to do it. the `File` object is mainly an api available for developers to interact with uploaded/generated files. --- – r3wt Jan 17 '21 at 20:08
  • Because I want to recreate an array of File object in order to use it with the PrimeNG FileUpload component into an edit mode view. So into the File Upload PrimeNG component I want to show the file realted to a specific item – AndreaNobili Jan 17 '21 at 21:03
  • and why on earth would you need the actual file contents to create `File` objects to show the previously uploaded files? you can just retrieve info about the uploaded images and create fake file objects for use with that component, right? – r3wt Jan 18 '21 at 15:22

2 Answers2

2

how can I retrieve a specific image from Firebase Storage service into one of this File object?

After a file is uploaded to Firebase Storage, there is no way in the Firebase JavaScript SDK to get it directly to a local file. While the iOS and Android SDKs have this option, the JavaScript SDK only allows downloading the data via a so-called download URL.

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
0

This is clearly shown in the console that File is a javascript array which may contain multiple uploaded image object. To get the first image object you do something like that -

File[0].objectURL.SafeUrlImpl

The previous line of code will retrieve the object URL.

HM Nayem
  • 2,287
  • 1
  • 12
  • 10