C# 文本文件上传和下载问题

发布于 2024-10-19 10:54:58 字数 472 浏览 5 评论 0原文

好的,我有一个将文本文件上传到网络服务器的应用程序,一切正常。 但是,下载文本文件时,文本文件上会神奇地出现一行

示例:

textfile contains = Hello World

downloaded textfile contains =                //notice the blank line here
                      Hello World

通常这不会成为问题,因为我只需创建一个临时文件并删除该行。

但是,由于文本文件包含加密数据,如果我创建一个新的临时文件来删除该行,它会完全混淆加密文本并创建 “错误数据”和“要解密的数据长度无效”错误。

我几乎 100% 确定这不是我的加密算法,因为文本文件是在上传之前输出的,并且它在未上传的文本文件上运行良好。

如果你们能帮助我那就太好了。任何解决办法都可以(无论它多么可怕/令人讨厌)。

Okay so I have an application which uploads a text file to a web server and all works fine.
However, a line magically appears on the text file when it is downloaded

example:

textfile contains = Hello World

downloaded textfile contains =                //notice the blank line here
                      Hello World

Normally this wouldnt be a problem as I would just create a temp file and delete the line.

However, as the text file contains encrypted data and if I create a new temp file to delete the line it completely messes with the encrypted text and creates
"Bad Data" and "length of data to decrypt is invalid" errors.

Im almost 100% sure its not my encryption algorithm as the text files are output before they are uploaded and it works fine on the non uploaded text files.

If you guys could help me that would be awesome. Any work around will do (no matter how horrible / nasty it is).

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

我做我的改变 2024-10-26 10:54:58

服务器和客户端是否运行相同系列的操作系统?我认为这可能是由于换行序列差异以及以不同模式(文本/二进制)上传和下载造成的。

如果数据经过加密或加密签名,您需要尽一切努力确保传输以二进制模式完成。

Does the server and client run the same family operating system? I'm thinking that this may be due to newline sequence differences, and uploading and downloading in different modes (text/binary).

If the data is encrypted or cryptographically signed, you want to do everything you can to make sure the transfers are done in binary mode.

梦屿孤独相伴 2024-10-26 10:54:58

下载代码是什么样的?

大胆猜测:您正在 Response.Write() 处理文本,而没有使用 Response.Clear() 来清除任何“aspx 文本”。另外,您需要该代码以 Response.End() 结尾,以防止进一步添加文本。

What does the download code look like?

Making a wild guess: you are Response.Write()ing the text, without a Response.Clear() to clear any "aspx text". Plus you need that code to end on a Response.End() to prevent further additions to the text.

甜柠檬 2024-10-26 10:54:58

看起来您的加密算法正在向您的文本附加以空结尾的字符串。

尝试以字节数组的形式加载网络服务器上的文本文件,并查看最后一个字节是否为“\0”。

It looks like your encryption algorithm is appending your text with null terminated string.

Try loading the text file on you webserver in a byte array and see if last byte is '\0'.

离旧人 2024-10-26 10:54:58

发生这样的事情有两个原因。

  1. 您正在对上传进行一些更改(例如解析文本和一些数据操作,您在其中引入了这一行)
  2. 您正在阅读文件并在下载之前对其进行操作...

检查代码并发布一些示例(如果您是)实际上操纵它。我已经使用 C# 上传了文件,效果很好。

您应该查看 Hanselman 的博客,了解一个简单的上传应用程序...它很简单。

There are two reasons something like this can happen.

  1. You are making some changes on upload(like parsing the text and some amount of data manipulation,where you introduce this line)
  2. You are readingthe file and manipulating it before you download it...

Check both the code and post some samples if you are actually manipulating it. I have uploaded files using c# and it works fine.

You should check Hanselman's blog for a simple upload application...It is straight forward.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文