User post their MP3s to my site and I would like to read the metadata from the files before they are stored in the CDN. TagLib-Sharp seems to be library to go for this, but I can't see any way to open a HttPostedFile, which I don't not want to save to disk, and retrieve the metadata.
Anybody have an example on how to do this with taglib-sharp?
Edit: It seems that IFileAbstraction can solve this. Anybody know how to use IFileAbstraction?
You would want to do something as follows. The caveat is that the steam has to be seekable an I do not know if HttpPostedFile.InputStream
is.
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) { }
}
来源:https://stackoverflow.com/questions/8106408/taglib-sharp-reading-metadata-from-httppostedfile-object