Trouble linking storage to database on Firebase with Vue.js

I'm currently diving into my Vue project integrating firebase to create locations with specialized images and data. I've been following a tutorial but it seems a bit outdated, especially when trying to connect Firebase storage with the database.

My main issue is not being able to successfully save the downloadable image URL in Firebase storage and then store it in the database. Can anyone offer some guidance or assistance with this? Thank you!

createLocation( {commit, getters}, payload) {
        const location = {
            title: payload.title,
            location: payload.location,
            description: payload.description,
            creationDate: payload.creationDate,
            rating: payload.rating,
            coordinates: payload.coordinates,
            filters: payload.filters,
            creatorId: getters.user.id
        }
        let imageUrl
        let key
        firebase.database().ref('locations').push(location)
            .then((data) => {
                key = data.key
                return key
            })
            .then(key => {
                const filename = payload.image.name
                const ext = filename.slice(filename.lastIndexOf('.'))
                console.log(payload.image)
                return firebase.storage().ref('locations/' + key + ext).put(payload.image)
            })
            .then(fileData => {
                imageUrl = fileData.metadata.getDownloadURL
                return firebase.database().ref('meetups').child(key).update({imageUrl: imageUrl})
              })
            .then(() => {
                commit('createLocation', {
                ...location,
                imageUrl:imageUrl,
                id: key
                })
            })
            .catch((error) => {
                console.log(error)
            })
    },

Answer №1

When referring to the metadata.downloadURL in the Firebase reference documentation, it is noted as:

deprecated

Instead, use Reference.getDownloadURL. This particular property will be eliminated in upcoming releases.

To obtain the download URL for a file now requires an additional trip to the server, necessitating another then block:

firebase.database().ref('locations').push(location)
    ...
    .then(key => {
        const filename = payload.image.name
        const ext = filename.slice(filename.lastIndexOf('.'))
        console.log(payload.image)
        return firebase.storage().ref('locations/' + key + ext).put(payload.image)
    })
    .then(fileData => {
        return fileData.ref.getDownloadURL();
    })
    .then(imageUrl => {
        return firebase.database().ref('meetups').child(key).update({imageUrl: imageUrl})
    })
    ...

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is the reason behind the presence of an exclamation mark in my URL while using Angular?

Recently, I ventured into the MEAN stack and decided to follow some tutorials to get a better understanding. In my journey, I utilized npm-views from Angular in an attempt to redirect an HTML a tag to another HTML file. However, as I navigated to localhos ...

Tips for coordinating external asynchronous JavaScript retrieval

Within my app.js file, I have the following code snippet: load(src) { var script = document.createElement('script'); script.src = src; script.async = true; document.head.appendChild(script); } for (var i=0; scripts.length; i++) { loa ...

JavaScript - Loading image from local file on Linux machine

I have a server running and serving an HTML page, but I am trying to display an image from a local drive on a Linux machine. I've tried using file://.., but it doesn't seem to be working for me on Ubuntu 18.04. There are no errors, the img tag ju ...

What is the best method for animating a line in THREE.js using TweenLite?

I've been trying to animate a 3D line using THREE.JS and TweenLite. However, the method that usually works well with the position of an object like a sphere is not yielding the desired results in this case. The reason for this discrepancy eludes me. ...

Discover the ultimate guide to creating an interactive website using solely JavaScript, without relying on any server-side

I'm facing a challenge: I have a desire to create a website that is mainly static but also includes some dynamic components, such as a small news blog. Unfortunately, my web server only supports static files and operates as a public dropbox directory. ...

Exploring the use of callbacks in React closures

After diving into a React related article, I delved deeper into discussions about closures and callbacks, checking out explanations on these topics from Stack Overflow threads like here, here, and here. The React article presented an example involving thr ...

Display and conceal automatically created input box using JavaScript

I am facing an issue with a form that contains a select dropdown and an input box. The input box should only be visible when the "Other" option is selected from the dropdown. The problem arises when a button clones this code, creating additional copies of ...

Seeking assistance with coding a beginner-level Google Chrome extension

Currently, I am working on developing a basic Google Chrome extension with 2 or 3 browser actions. I have been using Selenium IDE to capture the necessary steps in Firefox that I need for my project. However, I am unsure of how to translate these recorde ...

Jesting supplier, infusing elements

I find myself in a complex situation that I will do my best to explain, even if it may seem confusing. Imagine I have a customized provider called actionProvider within the module named core. This provider has the ability to register actions and then exec ...

Display the changing value at the beginning of the drop-down menu

I'm currently working on an AngularJS forEach loop where I need to display a dropdown list with dynamic values. The goal is to have the value stored in $scope.showCurrentProgram as the first selected element in the dropdown list when the page loads, a ...

Generating components dynamically at runtime following an HTTP request in VueJS

Is there a way to conditionally render VueJS components based on an Http request immediately upon application launch? I want to display component 1 if the response is successful, otherwise display component 2. Additionally, I would like the rendering of th ...

"Streamlining communication: Building a mail sending form with AJAX, JQuery

I am currently dealing with a dilemma on my website where I have 2 contact forms, and I am utilizing ajax jQuery to send emails via PHP. Everything works smoothly when I use a single form along with jQuery. However, when I try to adapt the jQuery code for ...

I am excited to create a Dynamic Routing system that selects specific elements from an array of objects using Typescript

1. crops-list.component.ts import { Component, OnInit } from '@angular/core'; import { ActivatedRoute } from '@angular/router'; @Component({ selector: 'app-crops-list', templateUrl: './crops-list.component.html' ...

Determine the height of an element within an ng-repeat directive once the data has been fetched from an

After sending an ajax request to fetch a list of products, I use angular's ng-repeat to render them. I am attempting to retrieve the height of a div element that contains one product in the list. However, the console always displays "0" as the result ...

Encountered an error while trying to import the module: Unable to locate module 'react-redux'

I keep encountering the following errors and I'm unsure of where I'm making a mistake. Any assistance would be greatly appreciated. I've made changes to my webpack configuration and updated the react-hot-webpack loader, but the errors persis ...

Having trouble executing a JavaScript function correctly when using an onclick event created within innerHTML in JavaScript

My goal is to trigger the loadInWhat function with an onclick event and populate my input field with id="what" using the value of LI function createDivBox(data){ document.getElementById("whatContainer").style.display="block"; document.get ...

increasing the size of an array in react javascript

componentWillMount(){ this.adjustOrder(); } componentDidMount(){} adjustOrder(){ var reorderedArray = []; this.state.reservation1.length = 9; for (var i = 0; i < this.state.reservation1.length; i++) { if(this.state.reservation1[i]){ r ...

Issue with React Material-UI drawer not functioning properly when invoking a child component function from the parent

Here is a piece of code I have for the App.js file: import React, { Component } from 'react'; import logo from './logo.svg'; import './App.css'; import Child from './child'; class App extends Component { render() ...

Developing a data table with JavaScript by parsing JSON data

Looking to generate a school timetable table using dummy JSON data. The JSON object structure is as follows: this._days=[ { "day": "", "config": {} }, { "day": "Monday", "config": { ...

Sending a group of checkboxes via Ajax using AngularJS

I am facing a challenge with making an ajax GET request where I need to submit an array of checkboxes, all with the same name. The checkboxes are defined as follows: type[] = new type[] = used type[] = refurbished The purpose of this is to fulfill the r ...