我已经制作了azure功能应用程序并部署到azure。应用程序将从指定的容器中获取zip文件并将其解压缩到另一个容器或指定的容器中。我的代码不是上传文件后5分钟说超时值。这是我的错误屏幕从azure日志屏幕错误图像
我的代码
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启动应用程序时,同样的代码也能工作。下面是工作Spring启动代码。
@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";
}
请帮助任何人解决问题。
1条答案
按热度按时间q1qsirdb1#
我看了一下,好像你的代码基本上是对的。你确定这不是由过程引起的需要超过5分钟吗?你的zip文件太大了吗?
你可以看看下面的文档,让函数超时设置更长,然后再试一次。
https://docs.microsoft.com/en-us/azure/azure-functions/functions-host-json#functiontimeout