我是nodejs和firebase的新手,但我需要上傳文件。我看到this教程,但無法獲得太多。我完全困惑。在這個教程中,是傳遞選擇文件的函數? 代碼:如何在nodejs中上傳文件
const keyFilename = "./my-private-api-key-file.json"; //replace this with api key file
const projectId = "my-project-id-should-go-here" //replace with your project id
const bucketName = `${projectId}.appspot.com`;
const mime = require('mime');
const gcs = require('@google-cloud/storage')({
projectId,
keyFilename
});
const bucket = gcs.bucket(bucketName);
const filePath = `./package.json`;
const uploadTo = `subfolder/package.json`;
const fileMime = mime.lookup(filePath);
bucket.upload(filePath, {
destination: uploadTo,
public: true,
metadata: {
contentType: fileMime,
cacheControl: "public, max-age=300"
}
}, function (err, file) {
if (err) {
console.log(err);
return;
}
console.log(createPublicFileURL(uploadTo));
});
function createPublicFileURL(storageName) {
return `http://storage.googleapis.com/${bucketName}/${encodeURIComponent(storageName)}`;
}
我要上傳文件時,用戶選擇了一個文件。任何人都可以提供我一些啓動?謝謝。