I'm trying to use Firebase cloud functions to upload an image onto storage. When I run the function from a browser, I receive a '0' response, indicating that it failed. Afterwards I check the logs and it displays the error:
Upload bad! [Error: ENOENT: no such file or directory, stat 'https://i2.wp.com/lifemadesimplebakes.com/wp-content/uploads/2018/03/How-To-Make-Fruit-Salad-680x680.jpg'] {
The image url does exist though. So I'm wondering why it's not working? Here's my whole cloud function:
const functions = require('firebase-functions'); const admin = require('firebase-admin'); exports.uploadTest = functions.https.onRequest(async (request, response) => { const url = 'https://i2.wp.com/lifemadesimplebakes.com/wp-content/uploads/2018/03/How-To-Make-Fruit-Salad-680x680.jpg'; admin.initializeApp(); const bucket = admin.storage().bucket('my-bucket.appspot.com'); bucket.upload(url, { destination: "myFolder/myFile.png" }).then(() => { console.log("Upload good!"); response.send('1'); return true }).catch(err => { console.error("Upload bad!", err); response.send('0'); }); })
https://stackoverflow.com/questions/65372182/firebase-function-upload-to-storage December 20, 2020 at 12:51AM
没有评论:
发表评论