- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我似乎无法使用 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
tofalse
.
小于 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/
我有以下正则表达式 /[a-zA-Z0-9_-]/ 当字符串只包含从 a 到z 大小写、数字、_ 和 -。 我的代码有什么问题? 能否请您向我提供一个简短的解释和有关如何修复它的代码示例? //var
我是一名优秀的程序员,十分优秀!