如何从Azure函数java发送pdf响应?

如何从Azure函数java发送pdf响应?,java,azure,azure-functions,Java,Azure,Azure Functions,有人能告诉我如何从Java中的HTTP触发器Azure函数发送pdf响应吗 触发该功能后,我需要从Azure存储读取pdf,并将pdf作为响应返回到浏览器。这对我来说很好: package com.function; import java.net.URISyntaxException; import java.security.InvalidKeyException; import java.util.*; import com.microsoft.azure.functions.annot

有人能告诉我如何从Java中的HTTP触发器Azure函数发送pdf响应吗


触发该功能后,我需要从Azure存储读取pdf,并将pdf作为响应返回到浏览器。

这对我来说很好:

package com.function;

import java.net.URISyntaxException;
import java.security.InvalidKeyException;
import java.util.*;
import com.microsoft.azure.functions.annotation.*;
import com.microsoft.azure.functions.*;

import com.microsoft.azure.storage.*;
import com.microsoft.azure.storage.blob.*;

public class HttpTriggerJava {
    @FunctionName("HttpTriggerJava")
    public HttpResponseMessage run(@HttpTrigger(name = "req", methods = { HttpMethod.GET,
            HttpMethod.POST }, authLevel = AuthorizationLevel.ANONYMOUS) HttpRequestMessage<Optional<String>> request,
            final ExecutionContext context) {
        context.getLogger().info("Java HTTP trigger processed a request.");

        try {
            CloudStorageAccount storageAccount = CloudStorageAccount.parse(
                    "{your storage connections tring}");
            CloudBlobClient blobClient = storageAccount.createCloudBlobClient();
            CloudBlobContainer container = blobClient.getContainerReference("{container name}");
            CloudBlockBlob blob = container.getBlockBlobReference("{filename}");

            byte[] content = new byte[blob.getStreamWriteSizeInBytes()];
            blob.downloadToByteArray(content, 0);

            return request.createResponseBuilder(HttpStatus.OK)
                .body(content)
                .build();

        } catch (InvalidKeyException | URISyntaxException e) {
            e.printStackTrace();
            return request.createResponseBuilder(HttpStatus.NOT_FOUND)
                .body(e.getMessage())
                .build();
        } catch (StorageException e) {
            e.printStackTrace();
            return request.createResponseBuilder(HttpStatus.INTERNAL_SERVER_ERROR)
                .body(e.getMessage())
                .build();
        }   
    }
}

将pdf作为响应返回到浏览器,是否要下载或在浏览器中显示?你的和这个一模一样吗?如果没有,请告诉我们您尝试了什么,以及您遇到了什么困难。@Jerry Liu:我想把它们作为响应发送到浏览器中并下载。请给我azure函数代码。是的,它与上一篇文章有关。My azure函数应从azure存储中获取pdf文件,并将响应作为pdf发送到浏览器,然后在浏览器中下载