在Firebase存储中使用函数for Firebase上传文件后,我想获取该文件的下载URL.
我有这个 :
...
return bucket
.upload(fromFilePath, {destination: toFilePath})
.then((err, file) => {
// Get the download url of file
});
Run Code Online (Sandbox Code Playgroud)
目标文件有很多参数.甚至一个名字mediaLink.但是,如果我尝试访问此链接,我会收到此错误:
匿名用户没有storage.objects.get访问对象...
有人可以告诉我如何获取公共下载Url?
谢谢
我正在尝试使用Node.js了解如何在Firebase存储中上传文件.我的第一次尝试是使用Firebase库:
"use strict";
var firebase = require('firebase');
var config = {
apiKey: "AIz...kBY",
authDomain: "em....firebaseapp.com",
databaseURL: "https://em....firebaseio.com",
storageBucket: "em....appspot.com",
messagingSenderId: "95...6"
};
firebase.initializeApp(config);
// Error: firebase.storage is undefined, so not a function
var storageRef = firebase.storage().ref();
var uploadTask = storageRef.child('images/octofez.png').put(file);
// Register three observers:
// 1. 'state_changed' observer, called any time the state changes
// 2. Error observer, called on failure
// 3. Completion observer, called on successful completion
uploadTask.on('state_changed', function(snapshot){
...
}, function(error) {
console.error("Something nasty happened", error);
}, …Run Code Online (Sandbox Code Playgroud) 当我删除Firebase数据库中的帖子时,我希望云功能相应地删除firebase存储中的帖子缩略图.我的问题是,当我试图删除缩略图时,我认为我没有正确找到图像文件.
这是我尝试过的:
const functions = require('firebase-functions')
const admin = require('firebase-admin')
const gcs = require('@google-cloud/storage')()
exports.deletePost = functions.database.ref('Posts/{pushId}').onWrite(event => {
const original = event.data.val()
const previous = event.data.previous.val()
const pushId = event.params.pushId
if (original === null)
return
const filePath = 'Posts/' + pushId + 'thumbnail.jpg'
const bucket = gcs.bucket('postsapp-12312')
const file = bucket.file(filePath)
const pr = file.delete()
return pr
});
Run Code Online (Sandbox Code Playgroud)
这就是我在日志中得到的
ApiError:找不到Object.handleResp上的Object.parseHttpRespBody(/user_code/node_modules/@google-cloud/storage/node_modules/@google-cloud/common/src/util.js:192:30)(/ user_code/node_modules/@ google-cloud/storage/node_modules/@ google-cloud/common/src/util.js:132:18)at/user_code/node_modules/@ google-cloud/storage/node_modules/@ google-cloud/common/src /来自Request.self.callback的Request.inResponse [as _callback](/user_code/node_modules/@google-cloud/storage/node_modules/retry-request/index.js:120:7)的util.js:465:12(/ user_code/node_modules/@google-cloud/storage/node_modules/request/request.js:188:22)在requestTmit(events.js:191:7)的emitTwo(events.js:106:13)处.(/user_code/node_modules/@google-cloud/storage/node_modules/request/request.js:1171:10)在emit.ene(events.js:96:13)的Request.emit(events.js:188:7)
我正在尝试按照firebase节点教程:https: //www.firebase.com/docs/web/quickstart.html
我的node.js应用程序崩溃了"TypeError:Firebase不是函数"错误.我的index.js文件:
var Firebase = require("firebase");
var firebaseRef = new Firebase("https://word-word-number.firebaseio.com/");
Run Code Online (Sandbox Code Playgroud)
第二行是发生崩溃的地方.
在我的package.json中,我有:
"firebase": "^3.0.2",
Run Code Online (Sandbox Code Playgroud)
和
"node": "5.11.0"
Run Code Online (Sandbox Code Playgroud) 400当我尝试删除目录时,FirebaseStorage始终返回错误,例如以下内容始终返回错误400.
let storageRef = FIRStorage.storage().reference().child("path/to/directory")
storageRef.deleteWithCompletion { (error) in
print("error: \(error)") // always prints error code 400
}
Run Code Online (Sandbox Code Playgroud)
但是,删除文件工作正常,例如不会返回错误:
let storageRef = FIRStorage.storage().reference().child("path/to/file.jpg")
storageRef.deleteWithCompletion { (error) in
print("error: \(error)") // works fine, error is nil
}
Run Code Online (Sandbox Code Playgroud)
我在这里做错了什么?我不认为它不受FirebaseStorage的支持,因为从目录中逐个删除文件会非常蹩脚(特别是如果所述目录有100或1000个).
我正在使用Jest来测试我的firebase功能.这一切都在浏览器中,因此我与服务器端的firebase没有任何冲突.当我使用firebase.auth()或firebase.database()一切正常.当我尝试使用firebase.storage()我的测试失败.
这是我的firebase导入和初始化:
import firebase from 'firebase';
import config from '../config';
export const firebaseApp = firebase.initializeApp(config.FIREBASE_CONFIG);
export const firebaseAuth = firebaseApp.auth();
export const firebaseDb = firebaseApp.database();
Run Code Online (Sandbox Code Playgroud)
我有一个imageUtils文件,其中包含上传功能:
import { firebaseApp } from './firebase';
export const uploadImage = (firebaseStoragePath, imageURL) => {
return new Promise((resolve, reject) => {
// reject if there is no imagePath provided
if (!firebaseStoragePath) reject('No image path was provided. Cannot upload the file.');
// reject if there is no imageURL provided
if …Run Code Online (Sandbox Code Playgroud) javascript firebase jestjs firebase-authentication firebase-storage
我目前正在构建一个应用程序,并且正在尝试测试我使用Express创建的生产服务器环境.通过webpack-dev-server提供应用程序时,该应用程序运行正常,但当我的Express server.js由webpack捆绑并node server.bundle.js运行时,我收到有关Firebase存储的以下错误.
/Users/palcisto/Sites/sandbox/MTBparks/MTBparksMemberApp/server.bundle.js:533
var storage = _firebaseConfig2.default.storage();
^
TypeError: _firebaseConfig2.default.storage is not a function
Run Code Online (Sandbox Code Playgroud)
节点最终只是切换到运行我的开发环境.
下面是我package.json的依赖项和npm脚本,后面是我终端的日志.
我在'_firebaseConfig2.default.storage上所做的所有google/stackoverflow搜索都不是一个函数'.
的package.json
{
"name": "mtbparks-member-app",
"version": "0.1.0",
"main": "index.html",
"scripts": {
"start": "if-env NODE_ENV=production && npm run start:prod || npm run start:dev",
"start:dev": "webpack-dev-server --inline --content-base build/ --history-api-fallback && postcss --use autoprefixer -d build src/styles.css",
"start:prod": "npm run build && node server.bundle.js",
"build:client": "webpack && postcss --use autoprefixer -d build src/styles.css",
"build:server": "webpack --config webpack.server.config.js",
"build": "npm run …Run Code Online (Sandbox Code Playgroud) 我在 Node.js 中使用 Cloud Functions for Firebase,其中使用 excel4node lib 从对象导出 excel 文档,现在的问题是,在wb.write('Excel.xlsx');我必须将该 excel 文件实际保存到某处之后,然后再将其发送到用户可以下载的前端它。
我尝试做的事情:
我知道 Firebase 有 Cloud Storage,但由于一些奇怪的原因,只有 google 知道,根据这篇文章:TypeError: firebase.storage 不是一个函数Firebase Storage 不再与 Node.js 一起使用。
我还阅读了有关 Google Cloud 存储的信息,但这只是通过付费服务实现的。
这里有一个教程: https: //mashe.hawksey.info/2017/06/cloud-functions-for-firebase-in-google-apps-script/但同样,您需要有付费计划。
我的问题是:是否有任何免费的方法可以使用 firebase 和 Nodejs 进行导出,以便我能够将导出的 excel 保存在某处并将其输出到前端,以便从用户那里下载?
node.js firebase google-cloud-platform google-cloud-functions