1

我正在尝试在前端放气 .xlsx 文件并在服务器端,在 asp net core 2.2 服务器中对其进行充气。

我尝试了一切,现在我有了这个:

//JS code
handleSaveFile = (file) => {
    var compressedFile = pako.deflate(JSON.stringify(file), { to: 'string' });
    this.setState({ file: compressedFile });
  } 

完全直截了当,pako.deflate 就足够了。

现在在后端,我尝试了所有方法,但根据文档,结果如下: 在此处输入图像描述

我也试过 GZipStream,但结果是一样的。我找不到任何关于压缩/解压缩的信息,但有很多关于其他方式的信息。

4

1 回答 1

1

看看这个,希望对你有帮助:

客户:

let output = pako.gzip(JSON.stringify(obj));

服务器:

public static string Decompress(byte[] data)
{
    // Read the last 4 bytes to get the length
    byte[] lengthBuffer = new byte[4];
    Array.Copy(data, data.Length - 4, lengthBuffer, 0, 4);
    int uncompressedSize = BitConverter.ToInt32(lengthBuffer, 0);

    var buffer = new byte[uncompressedSize];
    using (var ms = new MemoryStream(data))
    {
        using (var gzip = new GZipStream(ms, CompressionMode.Decompress))
        {
            gzip.Read(buffer, 0, uncompressedSize);
        }
    }
    string json = Encoding.UTF8.GetString(buffer); 
    return json;
}

详情见: https ://stackoverflow.com/a/66825721/1979406

于 2021-03-27T00:05:32.430 回答