question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Handling sharp's output to upload into cloud storage buckets?

See original GitHub issue

Hi,

Not sure what would be the best approach to handle and upload the result of sharp’s transformations. To clarify, I have a google storage bucket that can upload (using google-cloud-node) pointing from a local file location, or more specifically stream from that local file location. example:

bucket.upload('/var/folders/8p/image.png', function(err, file, apiResponse) {
  // Your bucket now contains:
  // - "image.png" (with the contents of '/var/folders/8p/image.png')
  // `file` is an instance of a File object that refers to your new file.
});

or

fs.createReadStream('/var/folders/8p/...')
  .pipe(file.createWriteStream())
  .on('error', function(err) {})
  .on('finish', function() {
    // The file upload is complete.
  });

So my question is: is the best way to write sharp’s result into memory and then upload the file via location path, or is it possible to create a stream of the result and upload the result directly?

Sorry for the novice question in advance, I saw some discussions that were somewhat related, but didn’t really provide any direct solutions.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:11 (4 by maintainers)

github_iconTop GitHub Comments

4reactions
lovellcommented, Mar 16, 2017

Hello, you can stream the result.

Using the example at https://github.com/GoogleCloudPlatform/google-cloud-node#preview-2

const remoteWriteStream = gcs
  .bucket('my-existing-bucket')
  .file('zebra.jpg')
  .createWriteStream();

sharp(input)
  .resize(100, 100)
  .pipe(remoteWriteStream);
0reactions
lovellcommented, Sep 27, 2019

@taruyar The two and a half year old example code is from https://github.com/googleapis/google-cloud-node so you’ll need to check/ask in that repo.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Upload objects from a filesystem | Cloud Storage
This page shows you how to upload objects to your Cloud Storage bucket from your local filesystem. An uploaded object consists of the...
Read more >
Protecting Yourself When Handling Contaminated Sharps
Sharps disposal containers must be readily accessible and located as close as feasible to the area where sharps will be used. In some...
Read more >
Upload files with Cloud Storage on Android - Firebase
Cloud Storage for Firebase allows you to quickly and easily upload files to a Cloud Storage bucket provided and managed by Firebase.
Read more >
Strategies for Sharps Disposal Container Use During Supply ...
Always place sharps in sharps disposal containers, not in the trash. ... Remain upright and stable during use and handling. Sharps Disposal Label ......
Read more >
Bulk Loading from Google Cloud Storage
If you already have a Google Cloud Storage account and use Cloud Storage buckets for storing and managing your data files, you can...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found