Azure功能状态代码500内部服务器错误 [英] Azure Function Status Code 500 internal server error

查看:137
本文介绍了Azure功能状态代码500内部服务器错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个逻辑应用程序,它将azure函数用作http触发器并获取返回字符串.当azure函数要接收Base64字符串,使用信息创建文件并上载到分配的存储帐户时,每次运行它时,我都会不断从Azure函数中获取状态代码500内部服务器错误.经过多次尝试和错误,我推断出问题发生在从Base64字符串创建文件以及创建Blob容器客户端的时候.

I have a logic app that uses azure function as a http trigger and gets a return string. When the azure function is to receive a Base64 string, create a file with the information and uploads to the assigned storage account, I keep getting status code 500 internal server error from the Azure function every time I run it. After many trial and error I deduced the problem occurs from when the file is to be created from the Base64 string and when the blob container client is created.

所以请帮助我.

更新:根据您的一些建议,我对应用程序的见解进行了几次运行,并两次出现此错误:

UPDATE: As per some of your suggestions, I implemented application insights ran it a few times and got this error occuring twice:

Azure.RequestFailedException

Azure.RequestFailedException

消息:执行函数:BlobAdd时发生异常指定的资源名称包含无效字符

Message: Exception while executing function: BlobAdd The specifed resource name contains invalid characters

状态:400(指定的资源名称包含无效字符.)

Status: 400 (The specifed resource name contains invalid characters.)

ErrorCode:InvalidResourceName

ErrorCode: InvalidResourceName

FailedMethod:Azure.Storage.Blobs.BlobRestClient + Container.CreateAsync_CreateResponse.

FailedMethod: Azure.Storage.Blobs.BlobRestClient+Container.CreateAsync_CreateResponse.

public static async Task<IActionResult> Run(
         [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req,
         ILogger log)
     {
         log.LogInformation("C# HTTP trigger function processed a request.");

     string requestBody = await new StreamReader(req.Body).ReadToEndAsync();

     return await Base64(requestBody);
 }

public static  async Task<IActionResult> Base64(string Base64Body)
{
    string HoldDBase = "";
    string TestBlobData = "null";

    if (Base64Body.Length > 10)
    {
        HoldDBase = Base64Body;
    }
    else
    {
        TestBlobData = "The Base64Body did not Pass";

        return (ActionResult)new OkObjectResult
           (
               new
               {
                   TestBlobData
               }
               );
    }

        //Connection string of the Storage Account Azure
        string ConnectionString = "xxxxxxxxx";

        // Create a BlobServiceClient object which will be used to create a container client
        BlobServiceClient blobServiceClient = new BlobServiceClient(ConnectionString);

        //Create a unique name of the container
        string ContainerName = "Base64_Blob" + Guid.NewGuid().ToString();

        //create the container and return a container client Object
        BlobContainerClient ContainerClient =  await blobServiceClient.CreateBlobContainerAsync(ContainerName); //Problem Here

        //create a local file in the Storage
        string localPath = "D:/Reliance/OlaForm/uploadsO";
        string fileName = "quickstart" + Guid.NewGuid().ToString() + ".txt";
        string localFilePath = Path.Combine(localPath, fileName);

        //convert string to bytes
        byte[] BaseBytes = Convert.FromBase64String(HoldDBase);

         //create file in local data
         await File.WriteAllBytesAsync(localFilePath,BaseBytes); //Problem Here        

      //get reference to a blob
      BlobClient blobclient = ContainerClient.GetBlobClient(fileName);

      // Open the file and upload its data
      FileStream uploadFileStream = File.OpenRead(localFilePath);
      await blobclient.UploadAsync(uploadFileStream);
     // blobclient.Upload(uploadFileStream);
      uploadFileStream.Close();

      //blob id from blobclient and return it
      TestBlobData = blobclient.ToString();

    TestBlobData = HoldDBase;
    return (ActionResult)new OkObjectResult
    (
        new {
            TestBlobData
        }
        );
}

推荐答案

您正在尝试写入"D"磁盘.由于Azure功能无法直接访问磁盘,因此在尝试写入不存在的磁盘时会出现500错误.

You are trying to write to the "D" disk. Since the Azure function does not have direct access to disks, you get a 500 error when trying to write to a disk that does not exist.

要从Azure函数写入文件,可以使用Azure存储SDK.

To write to a file from an Azure function you can use the Azure Storage SDK.

这篇关于Azure功能状态代码500内部服务器错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆