Ich bin ein Neuling in NodeJs und Firebase, aber ich muss Dateien hochladen. Ich sah this Tutorial aber konnte nicht viel greifen. Ich bin total verwirrt. In diesem Tutorial, welches ist die Funktion um die ausgewählte Datei zu übergeben? der Code:So laden Sie die Datei in 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)}`;
}
Ich möchte Datei hochladen, wenn der Benutzer eine Datei auswählt. Kann mir jemand etwas zum starten geben? Vielen Dank.