Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to get original file with formidable? #616

Closed
TayPark opened this issue Apr 24, 2020 · 3 comments
Closed

How to get original file with formidable? #616

TayPark opened this issue Apr 24, 2020 · 3 comments

Comments

@TayPark
Copy link

TayPark commented Apr 24, 2020

Support plan

  • which support plan is this issue covered by? (e.g. Community, Sponsor, or
    Enterprise):
  • is this issue currently blocking your project? (yes/no):
  • is this issue affecting a production system? (yes/no):

Context

  • node version: (nodenv) 12.14.1
  • module (formidable) version: latest
  • environment (e.g. node, browser, native, OS): WSL2, Ubuntu 18.04 LTS
  • used with (i.e. popular names of modules): express
  • any other relevant information: -

What problem are you trying to solve?

Hello again. I have to resize(with sharp) image from formidable, how to get this? Should I save file before resize it?

All I want is here. parse req and resize immediately.

form.parse(req, (err, fields, files) => {
  Array.isArray(files.imgFile) ? resize.generateThumbnail(files.imgFile[0]) : resize.generateThumbnail(files.imgFile)
// 
})
@auto-comment
Copy link

auto-comment bot commented Apr 24, 2020

Thank you for raising this issue! We will try and get back to you as soon as possible. Please make sure you format it properly, followed our code of conduct and have given us as much context as possible.
/cc @tunnckoCore @GrosSacASac

@tunnckoCore
Copy link
Member

tunnckoCore commented Apr 24, 2020

Hey there again :)

There's no such thing as "original file" currently. The file is directly streamed/written to the file system in OS's temporary directory or the defined upload dir. From there you can do your thing.

In the future we will allow the users to directly access the buffer/stream of an incoming file, so Formidable will not even touch the file system and the users will be able to decide what to do with it.

The #360 kind of is about that.

So, in your case, you can get the file path from the files and move, resize, read and etc.

Screenshot_20200425_022225

@GrosSacASac
Copy link
Contributor

GrosSacASac commented Dec 27, 2020

files.imgFile.path (or files.imgFile[0].path) contains the filename that was just saved.

If you don't want intermediate files, use options.fileWriteStreamHandler (which was introduced in #666) and construct a buffer. Then on('end') you can process the buffer with sharp.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants