更新时间:2022-06-16 21:17:29
文件损坏的原因是由于以下代码行:
The reason your file is corrupted is because of the following line of code:
cloudFile.UploadFromStreamAsync(fileStream);
基本上,您正在启动一个异步过程,但不等待它完成.要解决此问题,您可以执行以下任一操作:
Essentially you're starting an async process but not waiting for it to complete. To fix, you could do either of the following:
使用此方法的sync
版本:
cloudFile.UploadFromStream(fileStream);
或者,等待async
方法完成(推荐):
Or, wait for async
method to finish (recommended):
await cloudFile.UploadFromStreamAsync(fileStream);
请注意,如果您使用的是异步方法,则还需要使调用方法也异步.
Please note that if you're using async method, you would need to make the calling method async as well.