RESTSHARP向二进制流添加内容类型和内容插件

发布于 2025-01-29 12:09:05 字数 1016 浏览 4 评论 0原文

我们正在参与一个流程,在该过程中,我们为供应商提供AWS S3签名符,使他们可以将文件上传到S3存储桶。

该过程非常简单:

  1. 他们通过我们在AWS中发布的API / lambda函数向我们索取签名。
  2. 我们返回S3签名。
  3. 他们使用SignedUrl发布二进制文件(在这种情况下,是压缩.zip文件)。

尽管我们没有所有代码,但他们分享了有关实际后操作的该片段。 (有趣的是,他们使用的是 put 方法...不确定这是否重要)。

问题发生在步骤3中。他们的服务上传了二进制文件,如果将二进制文件更改为.txt,我们会看到以下其他元素已添加到.zip中。

--6de81f1b-be80-44de-8a14-7e023c92fcf3
Content-Type: application/octet-stream
Content-Disposition: form-data; name="file"; filename="H22101_0031_087.zip"

这会大大改变.zip文件的结构,从而导致校验和操作使我们无法解压缩文件...本质上,除非我们将这些附加元素剥离,否则它不是有效的。

负责发布二进制的代码非常简单:

var dataFileUploadRequest = new RestRequest();
dataFileUploadRequest.Method = Method.Put;
dataFileUploadRequest.AddFile("file", sdpData, documentFileName);
dataFileUploadRequest.RequstFormat = DataFormat.Binary;

他们通过使用HTTPCLIENT而不是RestSharp实施了解决方法...但是,我们希望更好地理解为什么会发生这种情况。

有谁知道为什么RestSharp的库会附加此其他内容类型,内容分配...甚至是.zip的二进制内容周围的奇怪的GUID(似乎是一种交易ID)?

We are participating in a process where we provide a vendor with AWS S3 SignedURLs that allow them to upload files to an S3 bucket.

The process is quite simple:

  1. They request a signedurl from us via an API / Lambda function we've published in AWS.
  2. We return an S3 signedurl.
  3. They use the signedurl to POST a binary file (in this case, a compressed .zip file).

While we don't have all of their code, they shared this snippet regarding the actual POST operation. (interesting to note, they're using the PUT method...not sure if that matters).

The problem occurs in Step 3. Their service uploads the binary file and, if we change the binary file to .txt, we see the following additional elements have been added to the .zip.

--6de81f1b-be80-44de-8a14-7e023c92fcf3
Content-Type: application/octet-stream
Content-Disposition: form-data; name="file"; filename="H22101_0031_087.zip"

This alters the structure of the .zip file considerably, causes checksum operations to fail and prevents us from decompressing the file...essentially it isn't a valid .zip unless we strip these additional elements out.

The code responsible for posting the binary is quite simple:

var dataFileUploadRequest = new RestRequest();
dataFileUploadRequest.Method = Method.Put;
dataFileUploadRequest.AddFile("file", sdpData, documentFileName);
dataFileUploadRequest.RequstFormat = DataFormat.Binary;

They implemented a workaround by using httpclient instead of restsharp...however, we would like to better understand why this is happening.

Does anyone know why restsharp's libraries would append this additional Content-Type, Content-Disposition...and even that strange guid (which appears to be a sort of transaction id) around the .zip's binary contents?

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文