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.

Question: Best way to load and save files from a buffer when file type is not known

See original GitHub issue

I’m loading images from the IFormFile container. I’m not sure what the best way is to find the image type so that I can save the images in the original format they were uploaded in. IFormFile.ContentType might not be reliable. I’m aware that libvips sniffs the first few bytes when loading a file from disk, is there a way to replicate that behaviour in this library? Perhaps to sniff from the intermediary buffer I’m using to load the image.

Issue Analytics

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

github_iconTop GitHub Comments

kleisaukecommented, Jun 20, 2019

libvips has two useful functions to quickly identify the image type:

I just made these functions available in NetVips with commit

Note that these functions will not detect truncated images, it just performs some basic verification of image metadata. For example, reading a buffer with GIF89a will result in VipsForeignLoadGifBuffer.

If you also want to detect broken images, you can use this:

kleisaukecommented, Jun 23, 2019

NetVips 1.1.0-rc3 is released on NuGet. If there’s nothing reported for a week, this will become 1.1.0 final.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Opening a buffer as a file - javascript
I want to save I/O, and read the content line by line like a file. Using this library, the file data is accessed...
Read more >
How to save a specific file in a different buffer?
There are several ways possible to do what you want, but all involve some kind of scripting. Using bufdo.
Read more >
Using Buffers in Node.js
A buffer is a space in memory (typically RAM) that stores binary data. In Node.js, we can access these spaces of memory with...
Read more >
How to Save and Load Your Keras Deep Learning Model
In this post, you will discover how to save your Keras models to files and load them up again to make predictions. After...
Read more >
How to get started with the ed text editor | Enable Sysadmin
Launch ed · Use the ed buffer · Cloud services · Generate text with ed · Save the buffer to disk · Read...
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 Post

No results found

github_iconTop Related Hashnode Post

No results found