TagLib-sharp: Reading metadata from HttpPostedFile object

爱⌒轻易说出口 提交于 2019-12-07 03:19:46

问题


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?


回答1:


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!