I\'m downloading in image from web to save it locally. It works great with any other image formats but it this method below fails with an argument exception when I try to read a
The base class libraries won't help you to deal with WebP images. However, if you only want to save the received file to the disk, you don't have to even know that you are dealing with a WebP images. You can simply treat the received data as a binary blob and dump it to a file, for example using Stream.CopyTo
and a FileStream
.
The Content-Type HTTP header will give you the mime type of the file you're downloading, and the Content-Disposition header can provide you with a filename and extension (though you might have to do some parsing). You can access those using HttpWebResponse.ContentType
and HttpWebResponse.Headers["Content-Disposition"]
.