问题
This is my code for
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};
Now code is working file is uploading but size of file is zero and on downloading its opening as a text file. Please Help
来源:https://stackoverflow.com/questions/52616023/file-size-is-zero-bytes-on-uploading-image-on-google-cloud-storage-nodejs