TagLib-sharp: read metadata from an HttpPostedFile object

A user publishes his MP3 files on my site, and I would like to read the metadata from the files before they are saved to the CDN. TagLib-Sharp seems to be the library for this, but I see no way to open the HttPostedFile, which I don't want to save to disk and retrieve metadata.

Does anyone have an example on how to do this with taglib-sharp?

Edit: It seems that IFileAbstraction can solve this problem. Does anyone know how to use IFileAbstraction?

+6
source share
1 answer

You would like to do something as follows. The caveat is that steam needs to be searched, and I don't know if there is an HttpPostedFile.InputStream .

 TagLib.File myFile = TagLib.File.Create(new HttpPostedFileAbstraction(postedFile)); public class HttpPostedFileAbstraction : TagLib.File.IFileAbstraction { private HttpPostedFile file; public HttpPostedFileAbstraction(HttpPostedFile file) { this.file = file; } public string Name { get { return file.FileName; } } public System.IO.Stream ReadStream { get { return file.InputStream; } } public System.IO.Stream WriteStream { get { throw new Exception("Cannot write to HttpPostedFile"); } } public void CloseStream (System.IO.Stream stream) { } } 
+5
source

Source: https://habr.com/ru/post/901352/


All Articles