简体   繁体   English

MemoryStream:本地还是没有?

[英]MemoryStream: local or not?

This is a really really simple question. 这是一个非常简单的问题。

Does the C# MemoryStream hold the data on the client or on the server? C# MemoryStream是否在客户端或服务器上保存数据?

For example I have a form that when posted uploads a file to my s3 bucket, but before it does that it reads the file into the memory stream. 例如,我有一个表单,该表单在发布时会将文件上传到我的s3存储桶中,但在此之前它将文件读入内存流中。 If that file has to be uploaded to the server first and held in a MemoryStream on the server, then that is bad and I need to rethink my solution. 如果该文件必须首先上传到服务器并保存在服务器上的MemoryStream ,那么那很不好,我需要重新考虑我的解决方案。

If the MemoryStream is local to the client, then that is good. 如果MemoryStream对客户端而言是本地的,那很好。

MemoryStream holds the data in your system's memory (RAM). MemoryStream将数据保存在系统的内存(RAM)中。 So it will be on whatever computer the code is running on. 因此它将在运行代码的任何计算机上。

In this case, it appears that you're saying your server-side code is using a MemoryStream to hold the data that comes in from a form POST. 在这种情况下,您似乎是在说服务器端代码正在使用MemoryStream来保存来自POST表单的数据。 Typically it's better to save the file to a temporary location on the disk, rather than trying to hold the entire file in memory. 通常,最好将文件保存到磁盘上的临时位置,而不是尝试将整个文件保存在内存中。

Or, if you're expecting to accept really large files, and you don't need to do any intermediate processing, you could just do a pass-through stream straight up to s3. 或者,如果您希望接受很大的文件,并且不需要执行任何中间处理,则可以直接进行直达s3的传递流。 The danger in this is that if the upload fails to complete, it'll probably take a little more effort to ensure things are cleaned up properly. 这样做的危险在于,如果上传无法完成,则可能需要花费更多的精力来确保正确清理内容。

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

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