stream.CopyTo - file empty. asp.net

后端 未结 3 1843
旧巷少年郎
旧巷少年郎 2021-01-07 16:15

I\'m saving an uploaded image using this code:

using (var fileStream = File.Create(savePath))
{
   stream.CopyTo(fileStream);
}

When the im

3条回答
  •  滥情空心
    2021-01-07 17:09

    I would recommend to put the following before CopyTo()

    fileStream.Position = 0
    

    Make sure to use the Flush() after this, to avoid empty file after copy.

    fileStream.Flush()
    

提交回复
热议问题