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

InputFile组件读取含变音字符的压缩包文件名显示异常问题

压缩包文件名乱码问题
  • 问题现象:读取包含变音字符的压缩包文件名(如 TestDocumentááá)时,entry.FullName 返回乱码,实际得到 TestDocument���.docx,预期应为 TestDocumentááá.docx
  • 代码场景:在处理上传文件的方法中,读取本地临时压缩包文件,遍历 ZipArchiveEntry 时出现该问题

相关代码

private async void OnInputFileChange(InputFileChangeEventArgs e)
{
    foreach (IBrowserFile file in e.GetMultipleFiles())
    {
        await using Stream stream = file.OpenReadStream((int)file.Size);
        MemoryStream memoryStream = new MemoryStream((int)file.Size);
        await stream.CopyToAsync(memoryStream);

        memoryStream.Position = 0;
        
        CancellationTokenSource cancellation = new CancellationTokenSource();
        byte[] buffer = new byte[file.Size];
        string UniqueFileName = Path.GetRandomFileName() + ".bin";
        string tmpfile = Path.GetTempFileName();
        tmpfile = e.File.Name;

        int bytesRead = 0;
        while ((bytesRead = await memoryStream.ReadAsync(buffer, cancellation.Token)) != 0)
        {
            using MemoryStream tmpMemoryStream = new MemoryStream(buffer, 0, bytesRead);

            using (var fs = new FileStream(tmpfile, FileMode.Append))
            {
                tmpMemoryStream.WriteTo(fs);
            }
        };

        using ZipArchive zipArchive = ZipFile.OpenRead(tmpfile);
        foreach (ZipArchiveEntry entry in zipArchive.Entries)
        {
            // entry.FullName 返回乱码:TestDocument���.docx

            //byte[] bytes = Encoding.UTF8.GetBytes(entry.FullName);
            //string text2 = Encoding.UTF8.GetString(bytes);
        }
    }
}

内容的提问来源于stack exchange,提问作者Durai Murugan

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.25 02:17:18