Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const storage = require('@google-cloud/storage');
- const fs = require('fs');
- /* temp */ const util = require('util');
- const gcs = storage({
- projectId: 'image...',
- keyFilename: './image....json'
- });
- const bucketName = 'image...app.com'
- const bucket = gcs.bucket(bucketName);
- let ImgUpload = {};
- ImgUpload.uploadToGcs = (req, res, next) => {
- const gcsname = req.file.originalname;
- const file = bucket.file(gcsname);
- const stream = file.createWriteStream({
- metadata: {
- contentType: "image/jpeg"
- }
- });
- stream.on('error', (err) => { /* this never executes */ });
- stream.on('finish', () => { /* this never executes */ });
- stream.end(req.file.buffer);
- }
- module.exports = ImgUpload;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement