0

I have made azure function app and deployed to azure. The app will take zip file from specified container and unzip it to another container or specified container. My code is not uploading file after 5min says timeout value. Here is my error screen error image from azure log screen

My code

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();

}

}

Same code works when i try from spirng boot apllication. Below is working spring boot code.

@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";
}

Please help anyone with solution.

brijesh Patil
  • 77
  • 1
  • 7

1 Answers1

0

I took a look, it seems your code is basically right. Do you make sure it is not caused by the process need more than 5 minutes? Is your zip file too big?

You can have a look of below doc, and let the function timeout settings be longer and try again.

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

Cindy Pau
  • 13,085
  • 1
  • 15
  • 27
  • No file size is just 320kb. Any way thanks, i solved it by referring [link](https://learn.microsoft.com/en-us/azure/storage/blobs/storage-quickstart-blobs-java-legacy) – brijesh Patil Nov 27 '20 at 06:46