使用Ubuntu上的.net核心将映像保存到磁盘(GCloud计算引擎)(Saving Image to disk using .net core on Ubuntu (GCloud Compute

编程入门 行业动态 更新时间:2024-10-25 12:17:40
使用Ubuntu上的.net核心将映像保存到磁盘(GCloud计算引擎)(Saving Image to disk using .net core on Ubuntu (GCloud Compute Engine))

我正在运行一些需要在磁盘上保存图像的代码。 我在谷歌计算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)

更多推荐

本文发布于:2023-08-01 23:43:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1368008.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:映像   磁盘   核心   引擎   GCloud

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!