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.

Forwarding files to another service.

See original GitHub issue

Hello,

First of all, thank you for this awesome library 😃

I have a question: How do you suggest forwarding the files that we receive in a resolver to another service? Currently, I write the file locally with stream.pipe(createWriteStream(filename)) and then forward that file to the other service that I want. But I think there should be a better way to achieve this.

Is it BusBoy that is stopping me from doing that? Because, I remember looking at formidable and it gives me the entire file object, but BusBoy seems to only give few of the fields from the File object and does some ‘magic’ under the hood?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
jaydensericcommented, Aug 22, 2018

When resolving the upload, I suggest:

  1. Create a unique file ID.

  2. Store the image under that ID in the cloud (e.g. S3, Digital Ocean Spaces, etc.).

  3. Use a thumbnailing/CDN service like imgix. Use it to extract image metadata.

  4. If the metadata is not valid, delete the S3 file and resolve validation errors.

  5. In your database, record the image under the file ID along with key bits of metadata (user ID, image dimensions, etc.).

  6. Make an Image type. Mine looks like this:

    screen shot 2018-08-22 at 5 18 26 pm

    The url resolver simply constructs an imgix url for the file ID. If you’re lazy you could just make it return the base URL, and document that the user needs to append their own query string for size, etc.

2reactions
mike-marcaccicommented, Aug 21, 2018

Hi @bhargavcp,

You shouldn’t need to create an intermediary file, but should simply be able to pipe the upload’s contents to your external service. The fields that are available (name, type, etc) are everything that is available before the entire content has streamed in. Anything that is calculated from the actual contents (a hash, size, etc) require that the stream be completely consumed. If you need any of these, you can use the createReadStream() API from v7.0.0 to compute these while the upload’s contents stream to a permanent location:

const { filename, mimetype, createReadStream } = await upload

// pipe contents to a hash function
createReadStream()
  .on('error', handleError)
  .pipe(hash)

// pipe contents to S3, Google Storage, SAN, etc
createReadStream()
  .on('error', handleError)
  .pipe(destination)
Read more comments on GitHub >

github_iconTop Results From Across the Web

Forwarding multipart/form-data to different service (python ...
Problem I am facing is not able to forward request data and files attached as it is, below is code example. @post('/') def...
Read more >
.forward Files (System Administration Guide, Volume 3)
Users can create a .forward file in their home directories that sendmail uses to redirect mail or send mail to a custom set...
Read more >
Port Forwarding for File Sharing
We explain how to use port forwarding to transfer files and describe the types of file sharing that use port forwarding.
Read more >
How to Send Large Files Over the Internet - PCMag
Here are several ways to send large files over the internet. Store Files Online. icloud. One easy solution is to upload the file...
Read more >
How to Use Store-and-Forward Transfers - TechDocs
A store-and-forward transfer can be used to transfer a file indirectly when a destination system is not available. You can send a file...
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