Reputation: 91
Here is my fileUploadService file:
import crypto from 'crypto';
var storage = require('@google-cloud/storage')();
uploadFile(req, bucket, next) {
if (!req.file) {
return next();
}
const gcsname = req.file.originalname;
const file = bucket.file(gcsname);
const stream = file.createWriteStream({
metadata: {
contentType: req.file.mimetype
}
});
stream.on('error', (err) => {
req.file.cloudStorageError = err;
next(err);
});
/*stream.on('finish', () => {
req.file.cloudStorageObject = gcsname;
file.makePublic().then(() => {
req.file.cloudStoragePublicUrl = this.getPublicUrl(gcsname);
next();
});
});*/
stream.end(req.file.buffer);
}
I have to make the file accessible for only sender and receiver. Is there anyway to achieve this?
Upvotes: 1
Views: 181
Reputation: 617
Signed URLs are designed for this purpose.
https://cloud.google.com/storage/docs/access-control/signed-urls
This SO question has an example of generating a signed URL in node.js
Create signed URLs for Google Cloud Storage with node.js for direct upload from browser
Upvotes: 1