TagLib-sharp:从 HttpPostedFile 对象读取元数据

发布于 2024-12-15 07:23:22 字数 234 浏览 2 评论 0原文

用户将他们的 MP3 发布到我的网站,我想在将文件存储到 CDN 之前从文件中读取元数据。 TagLib-Sharp 似乎是实现此目的的库,但我看不到任何方法来打开 HttPostedFile(我不想将其保存到磁盘)并检索元数据。

有人有关于如何使用 taglib-sharp 执行此操作的示例吗?

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

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

白芷 2024-12-22 07:23:22

您可能想要执行以下操作。需要注意的是,蒸汽必须是可查找的,我不知道 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) { }
}

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) { }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文