简体   繁体   中英

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?

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. 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.

If the MemoryStream is local to the client, then that is good.

MemoryStream holds the data in your system's memory (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. 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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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