多次使用 Stream
我正在尝试使用 HttpPostedFile.InputStream 将图像文件上传到存储库,并使用同一流将其大小调整为不同的缩略图大小。
- 步骤 1. 使用 Stream sm = HttpPostedFile.InputStream 我能够 文件上传成功。
- 步骤2.使用相同的流将图像调整为不同的尺寸。 但我总是收到错误,说正在使用流。
假设如果我跳过步骤 1 并仅执行步骤 2,我可以将输入流(图像)的大小调整为不同的大小。基本上它让我只使用一次 inputStream 。
如何实现按顺序处理步骤 1 和步骤 2?
我确实尝试将 inputStream 存储到变量中,并为每个步骤使用单独的副本,但没有成功。
有人可以建议/帮助我吗?
非常感谢
I am trying to upload an image file to a repository using HttpPostedFile.InputStream and resize to different thumbnail sizes using the same stream.
- Step 1. Using Stream sm = HttpPostedFile.InputStream I am able to
upload the file successfully. - Step 2. Use the same stream to resize the image to different sizes.
But always I get error saying that stream is being used.
Suppose if I skip step 1 and perform only step 2, I am able to resize the inputstream (images) to different size. Basically it is letting me to use the inputStream only once.
How can I achieve to process both step 1 and 2 sequentially ?
I did try storing the inputStream to a variable and used separate copy for each step but no luck.
Can someone suggest/help me ?
Thank you very much
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您在重用 Stream.Position 之前将其设置为 0 吗?
通过存储多个变量,您可能只是复制对内存中同一对象的引用。
You did set Stream.Position to 0 before reusing it?
By storing in multiple variables you're probably only duplicating the reference to the same object in memory.
如果您使用此流将多个不同的图像上传到服务器,您可能希望为要上传的每个文件打开一个新流,而不是尝试使用单个流上传所有文件。
If you're using this stream to upload several different images to a server, you probably want to open a new stream for each file you're uploading, rather than trying to upload all of them with a single stream.