简体   繁体   中英

How Can I Return Specified Image Size From Google Cloud Storage With Node API?

I'm using cloud storage and it is working well, I just don't want to return the full-size image every time. I'm wondering if there is a way to specify a width to resize an image to when I request it?

Here is the WORKING code. I just need to return smaller images, say, 300px wide (maintaining original aspect ratio). This number could change or fluctuate, so I don't want to save a ton of different versions at different sizes unless I absolutely have to.

var fileName = "Image.png";

var stream = bucket.file(fileName).createReadStream();

res.writeHead(200, { 'Content-Type': imageInfo.mime_type });

stream.on('data', function (data) {
  res.write(data);
});

stream.on('error', function (err) {
  console.log('error reading stream', err);
});

stream.on('end', function () {
  res.end();
});

I've found this site explaining how to do this in PHP, so I'm guessing there is probably a way to do this in node?

https://cloud.google.com/appengine/docs/standard/php/googlestorage/images

这篇文章应该会让你走上正轨 “使用谷歌云平台上传、调整和提供图像”@Lipis https://medium.com/google-cloud/uploading-resizing-and-serving-images-with-google -cloud-platform-ca9631a2c556

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM