TagLib-sharp:从HttpPostedFile对象读取元数据 [英] TagLib-sharp: Reading metadata from HttpPostedFile object

查看:95
本文介绍了TagLib-sharp:从HttpPostedFile对象读取元数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

用户将其MP3发布到我的网站,我想从文件中读取元数据,然后再将它们存储在CDN中. TagLib-Sharp似乎是可用于此目的的库,但是我看不到任何打开HttPostedFile的方法,我不想将其保存到磁盘并检索元数据.

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.

有人举过一个如何使用taglib-sharp做到这一点的例子吗?

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

看来IFileAbstraction可以解决这个问题.有人知道如何使用IFileAbstraction吗?

It seems that IFileAbstraction can solve this. Anybody know how to use IFileAbstraction?

推荐答案

您需要执行以下操作.需要说明的是,蒸汽必须易于寻找,我不知道HttpPostedFile.InputStream是否是蒸汽.

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) { }
}

这篇关于TagLib-sharp:从HttpPostedFile对象读取元数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆