我正在运行一些需要在磁盘上保存图像的代码。 我在谷歌计算ubuntu实例上使用.net core 1.0,为Image对象使用ImageProcessorCore库。
这是将映像从云存储桶提取到字节数组并尝试将其保存在磁盘上的代码。
if (!Directory.Exists(dir)) Directory.CreateDirectory(dir); if (!File.Exists(file)) { byte[] bytes = mediaAdapter.GetMedia(Id, Resolution); using (MemoryStream stream = new MemoryStream(bytes)) { Image image = new Image(stream); using (FileStream save = File.Create(file)) image.Save(save); } } using (FileStream read = File.OpenRead(file)) { Image img = new Image(read); return new BoundingRect(img.Width, img.Height); }此代码在运行.net核心的Windows机器上运行完美,但在我的计算引擎上停止执行,没有抛出异常。
PS:Directory.CreateDirectory(dir); 在计算引擎上创建目录。
任何帮助,将不胜感激。 谢谢
I am running some code that needs to save an Image on the disk. I am using .net core 1.0 on a google compute ubuntu instance, and ImageProcessorCore library for the Image objects.
This is the code that fetches the image from a Cloud Storage bucket into a byte array and tries to save it on disk.
if (!Directory.Exists(dir)) Directory.CreateDirectory(dir); if (!File.Exists(file)) { byte[] bytes = mediaAdapter.GetMedia(Id, Resolution); using (MemoryStream stream = new MemoryStream(bytes)) { Image image = new Image(stream); using (FileStream save = File.Create(file)) image.Save(save); } } using (FileStream read = File.OpenRead(file)) { Image img = new Image(read); return new BoundingRect(img.Width, img.Height); }This code runs perfectly on a windows machine running .net core but stops executing on my compute engine with no exceptions thrown.
PS: Directory.CreateDirectory(dir); creates the directory on the compute engine.
Any help would be appreciated. thx
最满意答案
问题与我试图保存文件的目录上的权限问题有关。(chown修复了问题)
Problem was related to permission issues on the directory i was trying to save the files in. (chown fixed the problem)
更多推荐
发布评论