【问题标题】:Azure function to upload file time outAzure函数上传文件超时
【发布时间】:2021-03-09 09:31:50
【问题描述】:

我已经制作了 azure 函数应用并部署到 azure。该应用程序将从指定容器获取 zip 文件并将其解压缩到另一个容器或指定容器。我的代码在 5 分钟表示超时值后没有上传文件。 这是我的错误屏幕 error image from azure log screen

我的代码

public class QueueTriggerFunction {
@FunctionName("QueueTriger")
public void execute(@QueueTrigger(name = "myQueueItem", dataType = "", queueName = "httpqueuereq", connection = "AzureWebJobsStorage") Details message,
         @BlobInput(
                  name = "file", 
                  dataType = "binary", connection = "AzureWebJobsStorage",
                  path = "{Path}") byte[] content,
                  final ExecutionContext executionContext) throws IOException {
    
     
     
     String connectStr = "DefaultEndpointsProtocol=https;AccountName=sdfswedfsf;AccountKey=dsdfsedfsfsffsf+dfdfdfd==;EndpointSuffix=core.windows.net";
        
     // Create a BlobServiceClient object which will be used to create a container client
     BlobServiceClient blobServiceClient = new BlobServiceClientBuilder().connectionString(connectStr).buildClient();
 
     //Create a unique name for the container
     String containerName = "output";

     // Create the container and return a container client object
     BlobContainerClient containerClient = blobServiceClient.getBlobContainerClient(containerName);
     
     

     
     InputStream targetStream = new ByteArrayInputStream(content);
     
     ZipInputStream zipIn = new ZipInputStream(targetStream);
     ZipEntry zipEntry = zipIn.getNextEntry();
     while(zipEntry != null) {
 
        // Get a reference to a blob
         BlobClient blobClient = containerClient.getBlobClient(zipEntry.getName());
        
         ByteArrayOutputStream outputB = new ByteArrayOutputStream();
         byte[] buf = new byte[1024];
         int n;
         while ((n = zipIn.read(buf, 0, 1024)) != -1) {
             outputB.write(buf, 0, n);
         }

        
            
         // Upload to container
         ByteArrayInputStream inputS = new ByteArrayInputStream(outputB.toByteArray());
        
         // Upload to container
         blobClient.upload(inputS, inputS.available(), true);
         
        
         
         zipEntry = zipIn.getNextEntry();
     }
     zipIn.close();

}

}

当我尝试使用 spirng boot 应用程序时,相同的代码可以工作。 下面是工作春季启动代码。

@PostMapping("/upload")
public String uploadFile(@RequestParam("file") MultipartFile file) throws IOException {
    
    String connectStr = "DefaultEndpointsProtocol=https;AccountName=fffffffff;AccountKey=qj/ffffffffff/UuCmERTQ1uNXzXuhCD+fffff==;EndpointSuffix=core.windows.net";
    
    // Create a BlobServiceClient object which will be used to create a container client
    BlobServiceClient blobServiceClient = new BlobServiceClientBuilder().connectionString(connectStr).buildClient();

    //Create a unique name for the container
    String containerName = "zipfiles";

    // Create the container and return a container client object
    BlobContainerClient containerClient = blobServiceClient.getBlobContainerClient(containerName);
    
    // Get a reference to a blob
    BlobClient blobClient = containerClient.getBlobClient(file.getOriginalFilename());
    
    // Upload to container
    blobClient.upload(file.getInputStream(), file.getSize(), true);
    
    return "Done";
}

请帮助任何人解决问题。

【问题讨论】:

    标签: java azure azure-blob-storage azure-queues


    【解决方案1】:

    我看了一下,看来你的代码基本是对的。你确定它不是由需要超过5分钟的过程引起的吗?您的 zip 文件是否太大?

    你可以看看下面的文档,把函数超时设置长一点再试试。

    https://docs.microsoft.com/en-us/azure/azure-functions/functions-host-json#functiontimeout

    【讨论】:

    • 没有文件大小只有 320kb。无论如何谢谢,我通过引用link解决了它
    猜你喜欢
    • 2018-02-16
    • 2017-06-27
    • 1970-01-01
    • 1970-01-01
    • 2020-09-04
    • 2017-06-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多