在 Ubuntu 上使用 .net 核心将图像保存到磁盘(GCloud 计算引擎)
Saving Image to disk using .net core on Ubuntu (GCloud Compute Engine)
我是运行一些需要在磁盘上保存图像的代码。
我在 google 计算 ubuntu 实例上使用 .net core 1.0,并为图像对象使用 ImageProcessorCore 库。
这是将图像从 Cloud Storage 存储桶提取到字节数组并尝试将其保存在磁盘上的代码。
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);
}
此代码在 windows 机器 运行 .net core 上完美运行,但在我的计算引擎上停止执行,没有抛出任何异常。
PS: Directory.CreateDirectory(目录);在计算引擎上创建目录。
如有任何帮助,我们将不胜感激。谢谢
问题与我试图保存文件的目录的权限问题有关。(chown 修复了问题)
我是运行一些需要在磁盘上保存图像的代码。 我在 google 计算 ubuntu 实例上使用 .net core 1.0,并为图像对象使用 ImageProcessorCore 库。
这是将图像从 Cloud Storage 存储桶提取到字节数组并尝试将其保存在磁盘上的代码。
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);
}
此代码在 windows 机器 运行 .net core 上完美运行,但在我的计算引擎上停止执行,没有抛出任何异常。
PS: Directory.CreateDirectory(目录);在计算引擎上创建目录。
如有任何帮助,我们将不胜感激。谢谢
问题与我试图保存文件的目录的权限问题有关。(chown 修复了问题)