You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

仅通过Base64字符串区分ZIP文件与DOCX/XLSX文件的方法咨询

仅通过Base64字符串区分ZIP文件与DOCX/XLSX文件的方法咨询

我现在碰到一个难题:有没有办法只借助Base64字符串来判断上传的文件是ZIP格式,还是DOCX/XLSX格式?这里特别说明一下——我没有文件扩展名可以用来辅助判断。

目前我找到的解决方案都需要结合文件扩展名才能生效,比如下面这段C#代码:

private static readonly byte[] ZIP_DOCX = { 80, 75, 3, 4 };

public static string GetMimeType(byte[] file, string fileName)
{
   string extension = Path.GetExtension(fileName) == null
                      ? string.Empty
                      : Path.GetExtension(fileName).ToUpper();

    if (file.Take(4).SequenceEqual(ZIP_DOCX))
    {
       mime = extension == ".DOCX" ? "application/vnd.openxmlformats-officedocument.wordprocessingml.document" : "application/x-zip-compressed";
    }
 }

但正如我之前提到的,这个方案对我完全不适用,因为我拿不到文件的扩展名。有没有其他可行的思路或者方法?

备注:内容来源于stack exchange,提问作者So_oP

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.15 08:58:10