简体   繁体   English

javascript上传者可以更改文件的二进制代码吗?

[英]Can javascript uploaders change file's binary code?

I am working in angular 2 project. 我正在angular 2项目中工作。 Back-end developers opened me a bug but I don't know what to do. 后端开发人员向我打开了一个错误,但我不知道该怎么办。 Here is the steps and details: 以下是步骤和详细信息:

1- I create a file named 1.txt and inside the file is just 1 . 1-我创建了一个名为1.txt的文件,并且文件内部只有1

2- I upload this file to the server via https://github.com/valor-software/ng2-file-upload this package 2-我通过https://github.com/valor-software/ng2-file-upload这个包将该文件上传到服务器

3- Then I ask to server to give me the files list and I click 1.txt to download. 3-然后我要求服务器给我文件列表,然后单击1.txt下载。

4- When download finished I see these lines inside the 1.txt: 4-下载完成后,我在1.txt中看到以下几行:

------WebKitFormBoundaryt97WFszMgfTbTJJm
Content-Disposition: form-data; name="file"; filename="11.txt"
Content-Type: text/plain

1
------WebKitFormBoundaryt97WFszMgfTbTJJm--

I just want to see 1 . 我只想看1 This result corrupts other files too like png, docx etc. 此结果也会破坏其他文件,例如png,docx等。

So, the back-end developers said to me that: While file is uploading, JS library shouldn't change the binary file content. 因此,后端开发人员对我说:在文件上传时,JS库不应更改二进制文件的内容。

But I can't see any settings to do that. 但是我看不到任何设置可以做到这一点。 What should I say to them? 我应该对他们说什么?

PS Back-end developers are far away from me and their project written in Java. PS后端开发人员离我很远,他们的项目用Java编写。

The library you are using will, by default, generate a multipart request body. 默认情况下,您使用的库将生成一个多部分请求主体。

This is normal. 这很正常。 This is standard . 这是标准的 This is what would happen if you used a regular (JavaScript-free) form submission to POST a file. 如果您使用常规(无JavaScript)表单提交来发布文件,则会发生这种情况。 This is how most server side systems expect files to be sent over HTTP. 这就是大多数服务器端系统期望文件通过HTTP发送的方式。

You could tell that to write their code to expect the data in that format. 您可以告诉他们编写他们的代码,以期望该格式的数据。

Alternatively you could look at the documentation for your library which says: 或者,您可以查看图书馆的文档,其中说:

disableMultipart - If 'true', disable using a multipart form for file upload and instead stream the file. disableMultipart-如果为“ true”,则禁用使用分段表单上传文件,而是流式传输文件。 Some APIs (eg Amazon S3) may expect the file to be streamed rather than sent via a form. 某些API(例如Amazon S3)可能希望文件被流式传输,而不是通过表单发送。 Defaults to false. 默认为false。

… and turn that option on. …然后打开该选项。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM