Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uploading Image #14

Open
MeerZaheen opened this issue Feb 18, 2020 · 4 comments
Open

Uploading Image #14

MeerZaheen opened this issue Feb 18, 2020 · 4 comments

Comments

@MeerZaheen
Copy link

MeerZaheen commented Feb 18, 2020

I can upload new image from postman but I cannot upload image from web app.

image

export const uploadImage = formData => dispatch => { dispatch({ type: LOADING_USER }); axios .post("/user/image", formData) .then(() => { dispatch(getUserData()); }) .catch(err => console.log(err)); };

@sshah98
Copy link

sshah98 commented Apr 10, 2020

I'm getting a similar error, it's related to a CORS issue

@vip110997
Copy link

Did anyone find a solution for this?

@sshah98
Copy link

sshah98 commented May 2, 2020

Yeah, the issue is due to the admin.js file and the service account associated with the functions folder.

Basically, in the functions folder, there is an admin.js file with the following code (if you set up local testing for functions: ex: firebase serve)

const admin = require("firebase-admin");
const serviceAccount = require("../db.json");
 admin.initializeApp({
   credential: admin.credential.cert(serviceAccount),
   databaseURL: "https://yourUrl.firebaseio.com",
 });
const db = admin.firestore();
module.exports = { admin, db };

simply remove the code related to the service account as such:

const admin = require("firebase-admin");
admin.initializeApp();
const db = admin.firestore();
module.exports = { admin, db };

This is what worked for me. Also, be careful if you're on the spark plan not to have too many requests within 100 seconds, otherwise, you'll get a CORS error.

@vip110997
Copy link

Thanks for the quick reply @sshah98. The code in my admin.js is as follows

const express = require("express"); const admin = require("firebase-admin"); admin.initializeApp(); var db = admin.firestore(); module.exports = { admin, db };

However, I am getting the same error

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants