gpt4 book ai didi

node.js - Firebase 有上传限制吗?

转载 作者:太空宇宙 更新时间:2023-11-03 23:13:28 24 4
gpt4 key购买 nike

我似乎无法使用 Busboy 的 Firebase 功能在 Firebase 存储中上传超过 5MB 的文件。错误返回:

ResumableUploadError: A resumable upload could not be performed. The directory, /tmp/.config, is not writable. You may try another upload, this time setting options.resumable to false.

小于 5mb 即可工作。如果 5mb 是限制,有解决办法吗?

编辑:

这是我的代码

  const functions = require('firebase-functions');
const admin = require('firebase-admin');
const express = require('express');

var serviceAccount = require('./serviceAccount.json');
admin.initializeApp(
{credential: admin.credential.cert(serviceAccount),
databaseURL:dbURL})
let gcs = admin.storage();
const bucketName = 'bucket name';

const app = express();
const api = functions.https.onRequest(app);

app.post('/addImage',(req,res)=>{

const busboy = new Busboy({ headers: req.headers });
let uploadData = null;
let origFileName;

busboy.on("file", (fieldname, file, filename, encoding, mimetype) => {
origFileName = filename
const filepath = path.join(os.tmpdir(), filename);
uploadData = { file: filepath, type: mimetype };
file.pipe(fs.createWriteStream(filepath));
});

let formData = new Map();
busboy.on('field', function(fieldname, val) {
formData.set(fieldname, val);
});

busboy.on("finish", () => {
const bucket = gcs.bucket(bucketName);
let uuid = UUID();
let dataURL = ''
let company = formData.get('company');
let eventCode = formData.get('eventCode');
let type = formData.get('type');
bucket
.upload(uploadData.file, {
uploadType: "media",
metadata: {
metadata: {
contentType: uploadData.type,
firebaseStorageDownloadTokens: uuid
}
},
destination: company+"/"+eventCode+"/"+type+"/"+origFileName
}).then(data=>{

let file = data[0];
dataURL = "https://firebasestorage.googleapis.com/v0/b/" + bucket.name + "/o/" + encodeURIComponent(file.name) + "?alt=media&token=" + uuid;


return res.status(200).send(result);
})
.catch(error =>{
console.log("error",error)
if (err) return res.status(500).send('Internal Server Error')
})

});
busboy.end(req.rawBody);
})

最佳答案

您的用例是否需要 options.resumable=true?如果这不会破坏您的用例,请将其切换为 false,它应该适合您。

Here您有关于 createWriteStream 的更多信息。

Resumable uploads are automatically enabled and must be shut off explicitly by setting options.resumable to false.

Resumable uploads require write access to the $HOME directory. Through config-store, some metadata is stored. By default, if the directory is not writable, we will fall back to a simple upload. However, if you explicitly request a resumable upload, and we cannot write to the config directory, we will return a ResumableUploadError.

There is some overhead when using a resumable upload that can cause noticeable performance degradation while uploading a series of small files. When uploading files less than 10MB, it is recommended that the resumable feature is disabled.

希望这有帮助。

编辑:

默认情况下它是启用的,您必须将其作为在 createWriteStream 中设置为 false 的选项传递,尝试这样做并查看它是否允许您上传。

例如像这样。

您必须像以前一样将文件路径传递给它,然后添加可恢复选项。

.createWriteStream({
resumable: false,
metadata: {
contentType: 'text/plain',
},
})

Here您有更多信息。

关于node.js - Firebase 有上传限制吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58446311/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com