Javascript 从内存流创建新图像对象在生产环境中不起作用,但在本地起作用

Javascript 从内存流创建新图像对象在生产环境中不起作用,但在本地起作用,javascript,c#,.net,google-cloud-storage,Javascript,C#,.net,Google Cloud Storage,目标:我目前正在从javascript获取一个文件,将其转换为字节数组的base64编码字符串,并将其传递给我的.net控制器。 然后,我将其转换回字节数组,创建一个新的内存流,从内存流创建一个图像对象,更改我需要更改的内容,然后将其带回内存流,然后上传到我的服务器 问题: 目前,我可以从前面提到的JavaScript编码中获取一个图像,并将其上传到服务器没有问题,但是当我试图将内存流转换为图像时,问题就出现了(这样我就可以调整它的大小)。我不知道为什么,但在我的本地机器上,它没有问题,也不会抛

目标:我目前正在从javascript获取一个文件,将其转换为字节数组的base64编码字符串,并将其传递给我的.net控制器。 然后,我将其转换回字节数组,创建一个新的内存流,从内存流创建一个图像对象,更改我需要更改的内容,然后将其带回内存流,然后上传到我的服务器

问题:
目前,我可以从前面提到的JavaScript编码中获取一个图像,并将其上传到服务器没有问题,但是当我试图将内存流转换为图像时,问题就出现了(这样我就可以调整它的大小)。我不知道为什么,但在我的本地机器上,它没有问题,也不会抛出任何错误,上传得非常好,调整了大小等等。然而,在我的linux服务器上,它在尝试从内存流创建映像之前到达日志行,它实际上没有抛出异常,只是停止工作并返回到我的控制器

我真的不确定发生了什么,但希望你们中的一些优秀人士能够提供帮助:)

代码:

public async Task<DataOpResult<string>> UploadFile(StorageUploadFile file, string FileGuid)
        {
            Console.WriteLine("Start Upload");
            DataOpResult<string> uploadFile = new DataOpResult<string>();
            uploadFile.Status = DataOpResultStatus.Success;
            
            try
            {
                //create storage client
                StorageClient storage = await StorageClient.CreateAsync(credential);
                Console.WriteLine("Created storage");

            //convert file data and create Image Object
            byte[] dataArray = Convert.FromBase64String(file.FileData);
            Console.WriteLine("Got byte array");
            Image imageVar = CreateImage(dataArray);
            Console.WriteLine("Converted image");

            //convert with aspect ratio
            var aspectRatio = (decimal)(imageVar.Width) / (decimal)(imageVar.Height);
            var newHeight = 150;
            int newWidth = (int)(newHeight * aspectRatio);

            //Resize Image
            Console.WriteLine("Resize image");
            Image resizedImage = ResizeImage(imageVar, newWidth, newHeight);
            MemoryStream resizedStream = new MemoryStream();
            resizedImage.Save(resizedStream, imageVar.RawFormat);
            Console.WriteLine("got new memory stream");
            // IUploadProgress defined in Google.Apis.Upload namespace
            var progress = new Progress<IUploadProgress>(
                p => Console.WriteLine($"bytes: {p.BytesSent}, status: {p.Status}")
            );

            // var acl = PredefinedAcl.PublicRead // public
            var acl = PredefinedObjectAcl.AuthenticatedRead; // private
            var options = new UploadObjectOptions { PredefinedAcl = acl };
            Console.WriteLine("Upload Images");
            var result = await storage.UploadObjectAsync("echochat-292801.appspot.com", $"{FileGuid}/{file.FileName}", file.FileType, resizedStream, options, progress: progress);
            Console.WriteLine(result.ToString());
            uploadFile.DataItem = result.MediaLink;                  
        } catch (Exception ex)
        {
            uploadFile.Status = DataOpResultStatus.Error;
            uploadFile.ThrownException = ex;
        }

        return uploadFile;
    }


public static Image CreateImage(byte[] imageData)
    {
        Image image;
        using (MemoryStream inStream = new MemoryStream())
        {
            inStream.Write(imageData, 0, imageData.Length);

            image = Image.FromStream(inStream);
        }

        return image;
    }
public异步任务上传文件(StorageUploadFile文件,字符串FileGuid)
{
Console.WriteLine(“开始上传”);
DataOpResult uploadFile=新的DataOpResult();
uploadFile.Status=DataOpResultStatus.Success;
尝试
{
//创建存储客户端
StorageClient存储=等待StorageClient.CreateAsync(凭证);
Console.WriteLine(“创建的存储”);
//转换文件数据并创建图像对象
byte[]dataArray=Convert.FromBase64String(file.FileData);
WriteLine(“获取字节数组”);
Image imageVar=CreateImage(数据数组);
Console.WriteLine(“转换图像”);
//用纵横比转换
var aspectRatio=(十进制)(imageVar.Width)/(十进制)(imageVar.Height);
var newHeight=150;
int newWidth=(int)(newHeight*aspectRatio);
//调整图像大小
Console.WriteLine(“调整图像大小”);
Image resizedImage=ResizeImage(imageVar、newWidth、newHeight);
MemoryStream resizedStream=新的MemoryStream();
resizedImage.Save(resizedStream,imageVar.RawFormat);
WriteLine(“获得了新的内存流”);
//在Google.api.Upload命名空间中定义的IUploadProgress
var progress=新的进度(
p=>Console.WriteLine($“字节:{p.BytesSent},状态:{p.status}”)
);
//var acl=PredefinedAcl.PublicRead//public
var acl=PredefinedObjectAcl.AuthenticatedRead;//private
var options=newuploadobjectoptions{PredefinedAcl=acl};
Console.WriteLine(“上传图像”);
var result=wait storage.UploadObjectAsync(“echochat-292801.appspot.com”,$“{FileGuid}/{file.FileName}”,file.FileType,resizedStream,选项,进度:进度);
Console.WriteLine(result.ToString());
uploadFile.DataItem=result.MediaLink;
}捕获(例外情况除外)
{
uploadFile.Status=DataOpResultStatus.Error;
uploadFile.ThrownException=ex;
}
返回上传文件;
}
公共静态映像CreateImage(字节[]imageData)
{
图像;
使用(MemoryStream inStream=新的MemoryStream())
{
流内写入(imageData,0,imageData.Length);
image=image.FromStream(流内);
}
返回图像;
}

正在运行
sudo apt get install libgdiplus

在服务器上,我的服务器工作了

文件数据、字符串是否实际被发送?字符串是如何编码的?是的,它是从javascript编码的base64。如果我不做任何调整,只是上传内存流,从不转换为图像,它会上传fine。你想让我添加如何工作的代码吗?注意:即使在服务器上,如果我根本不尝试调整图像大小,只需获取字符串,将其转换为内存流,然后上传,它也可以正常工作“停止工作,回到我的控制器。”怎么样?