Firebase Storage: How to store image url as an object property?

Ghulam Ahmed

I am uploading an image to firebase storage and retrieving its downloadURL. I have created a ADS node in firebase database and a newAd object in its node. What i want is that the downloadURL of that image is saved in newAd.picLink i.e property of newAd(Object).

addSubmitted.addEventListener("click", e => {
  const newAds = _db.ref("ADS").push();
  const newAd = {};

  const ref = firebase.storage().ref();
  const file = $("#exampleInputFile").get(0).files[0];
  const name = +new Date() + "-" + file.name;
  const task = ref.child(name).put(file, { contentType: file.type });

  task.snapshot.ref.getDownloadURL().then(downloadURL => {
    console.log("File available at", downloadURL);
    newAd.picLink = downloadURL; /*this isn't working how can i set 
    downloadURL as newAd objects property*/
  });
});
Frank van Puffelen

You're not writing anything to the database after the file has been uploaded. The simplest fix is to update newAds in there:

task.snapshot.ref.getDownloadURL().then(downloadURL => {
  console.log("File available at", downloadURL);
  newAdS.update({ picLink: downloadURL });
});

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Firebase how to get Image Url from firebase storage?

From Dev

How to get the value of Firebase storage download url and store it in firebase storage....,

From Dev

Firebase Storage - URL for image services

From Dev

Upload image from URL to Firebase Storage

From Dev

Upload Facebook image URL to Firebase Storage

From Dev

flutter firebase storage issue with image url

From Dev

Upload Facebook image URL to Firebase Storage

From Dev

How can i store to different storage buckets using Firebase Storage

From Dev

How do I save an image url from Firebase Storage to Firebase realtime data base, the image from my device

From Dev

How to upload the public url for an image uploaded to the Firebase Cloud Storage to the Realtime Database

From Dev

Cordova / Javascript Copy Image from URL to Store in Local Storage

From Dev

Store files in Firebase storage

From Dev

How to check progress of image upload to Firebase storage

From Dev

How to bind image in angularjs from firebase storage

From Dev

How would I reference an image in firebase storage?

From Dev

How to generate public url for a file in firebase storage?

From Dev

How to get URL from Firebase Storage getDownloadURL

From Dev

How to get URL from Firebase Storage getDownloadURL

From Dev

Store an object to storage to database

From Dev

Display images of Firebase Storage with a Firestore query to get image url in Flutter

From Dev

Firebase Cloud functions remove orphan image from storage using url

From Dev

How to store nested JSON object into Firebase Database?

From Dev

How to store Firebase Storage Items to local cache to save bandwidth costs?

From Dev

How to store firebase user email and password in Ionic Storage

From Dev

Can I store image on Firebase as file, instead of a data:url?

From Dev

Can I store image on Firebase as file, instead of a data:url?

From Dev

how to store an image on Google Cloud Storage sent by Android using Python

From Dev

how to store an image on Google Cloud Storage sent by Android using Python

From Dev

Efficiently store picture in Firebase Storage?

Related Related

  1. 1

    Firebase how to get Image Url from firebase storage?

  2. 2

    How to get the value of Firebase storage download url and store it in firebase storage....,

  3. 3

    Firebase Storage - URL for image services

  4. 4

    Upload image from URL to Firebase Storage

  5. 5

    Upload Facebook image URL to Firebase Storage

  6. 6

    flutter firebase storage issue with image url

  7. 7

    Upload Facebook image URL to Firebase Storage

  8. 8

    How can i store to different storage buckets using Firebase Storage

  9. 9

    How do I save an image url from Firebase Storage to Firebase realtime data base, the image from my device

  10. 10

    How to upload the public url for an image uploaded to the Firebase Cloud Storage to the Realtime Database

  11. 11

    Cordova / Javascript Copy Image from URL to Store in Local Storage

  12. 12

    Store files in Firebase storage

  13. 13

    How to check progress of image upload to Firebase storage

  14. 14

    How to bind image in angularjs from firebase storage

  15. 15

    How would I reference an image in firebase storage?

  16. 16

    How to generate public url for a file in firebase storage?

  17. 17

    How to get URL from Firebase Storage getDownloadURL

  18. 18

    How to get URL from Firebase Storage getDownloadURL

  19. 19

    Store an object to storage to database

  20. 20

    Display images of Firebase Storage with a Firestore query to get image url in Flutter

  21. 21

    Firebase Cloud functions remove orphan image from storage using url

  22. 22

    How to store nested JSON object into Firebase Database?

  23. 23

    How to store Firebase Storage Items to local cache to save bandwidth costs?

  24. 24

    How to store firebase user email and password in Ionic Storage

  25. 25

    Can I store image on Firebase as file, instead of a data:url?

  26. 26

    Can I store image on Firebase as file, instead of a data:url?

  27. 27

    how to store an image on Google Cloud Storage sent by Android using Python

  28. 28

    how to store an image on Google Cloud Storage sent by Android using Python

  29. 29

    Efficiently store picture in Firebase Storage?

HotTag

Archive