这是我的代码
const fs = require("fs");
const uuidv4 = require("uuid/v4");
const {Storage} = require("@google-cloud/storage");
const CLOUD_BUCKET = "priomark";
const storage = new Storage({
projectId: 'priomark-v3',
keyFilename: '../myapp/service.json'
})
const bucket = storage.bucket(CLOUD_BUCKET);
function upload(filess,cb) {
var options = {
metadata: {
contentType: filess.mimeType
}
};
var file = filess;
var gcsname = uuidv4() + file.name;
// console.log(file.type)
var files = bucket.file(gcsname);
const blod = files.createWriteStream(options);
blod.on('error',(err)=>{
console.log(err);
})
blod.on('finish', ()=>{
console.log("file Uploaded",gcsname);
cb(gcsname);
})
blod.end(file.buffer);
}
module.exports = {upload:upload};
现在代码正在上载工作文件,但文件大小为零,并且在将其开头下载为文本文件时。 请帮助