【问题标题】:How upload images to two different path/places in firebase?如何将图像上传到firebase中的两个不同路径/位置?
【发布时间】:2019-07-02 20:41:25
【问题描述】:

如何将上传的图像存储到 firebase 存储中的两个不同路径/位置?我试过了,但它不起作用

const { currentUser } = firebase.auth();

const ref = firebase.storage().ref().child(`images/${currentUser.uid}`);
const ref = firebase.storage().ref().child('photos')

const snapshot = await ref.put(blob);

blob.close();

【问题讨论】:

  • 您能否与我们分享任何错误或信息,说明为什么这不起作用?

标签: javascript firebase react-native firebase-storage


【解决方案1】:

好的,首先,你不能像这样重新声明变量(const ref = ...; 然后const ref = ....; 就在它下面)。其次,您需要对每个参考执行put。所以应该是这样的:

const { currentUser } = firebase.auth();

const ref1 = firebase.storage().ref().child(`images/${currentUser.uid}`);
const ref2 = firebase.storage().ref().child('photos')

const snapshot1 = await ref1.put(blob);
const snapshot2 = await ref2.put(blob);

blob.close();

或者,如果您想要更优化的代码:

const { currentUser } = firebase.auth();
const ref = firebase.storage().ref();

const imagesUpload = await ref.child(`images/${currentUser.uid}`).put(blob);
const photosUpload = await ref.child('photos').put(blob);

blob.close();

如果您想要更高级并且只有一个上传任务,请在此处阅读更多内容:https://cloud.google.com/storage/docs/json_api/v1/how-tos/batch

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多