Question: Best way to load and save files from a buffer when file type is not known
See original GitHub issueI’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:
- Created 4 years ago
- Comments:6 (4 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
libvips has two useful functions to quickly identify the image type:
vips_foreign_find_load
vips_foreign_find_load_buffer
I just made these functions available in NetVips with commit https://github.com/kleisauke/net-vips/commit/3fffefc9c2aab64fbc3928d629823595ab333335.
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 inVipsForeignLoadGifBuffer
.If you also want to detect broken images, you can use this: https://github.com/kleisauke/net-vips/blob/3fffefc9c2aab64fbc3928d629823595ab333335/samples/NetVips.Samples/Samples/IdentifyExtension.cs#L40-L63
NetVips 1.1.0-rc3 is released on NuGet. If there’s nothing reported for a week, this will become 1.1.0 final.