Как обрабатывать несколько файлов как составной запрос в AWS Lambda с помощью прокси-сервера API Gateway? - PullRequest
0 голосов
/ 14 июля 2020

Я ищу обходной путь, с помощью которого я могу обрабатывать несколько файлов как многостраничный запрос данных с AWS Lambda и API Gateway в качестве прокси.

Для обработки одного файла я следую this ,

public APIGatewayProxyResponseEvent handleRequest(APIGatewayProxyRequestEvent event, Context context)
{

    try
    {

        byte[] bytes = Base64.decode(event.getBody().getBytes());

        // Get the content-type header and extract the boundary
        Map<String, String> headers = event.getHeaders();

        String contentType = null;

        if (headers != null && !headers.isEmpty())
        {
            contentType =
                    headers.get("content-type") != null ? headers.get("content-type") : headers.get("Content-Type");
        }

        String[] boundaryArray = contentType.split("=");

        // Transform the boundary to a byte array
        byte[] boundary = boundaryArray[1].getBytes();

        ByteArrayInputStream content = new ByteArrayInputStream(bytes);

        // Create a MultipartStream to process the form-data
        MultipartStream multipartStream = new MultipartStream(content, boundary, bytes.length, null);

        // Create a ByteArrayOutputStream
        ByteArrayOutputStream out = new ByteArrayOutputStream();

        // Find first boundary in the MultipartStream
        boolean nextPart = multipartStream.skipPreamble();

        // Loop through each segment
        while (nextPart)
        {
            String header = multipartStream.readHeaders();

            context.getLogger().log("Headers:");

            context.getLogger().log(header);

            // Write out the file to our ByteArrayOutputStream
            multipartStream.readBodyData(out);

            // Get the next part, if any
            nextPart = multipartStream.readBoundary();
        }

            //Prepare an InputStream from the ByteArrayOutputStream
            InputStream fis = new ByteArrayInputStream(out.toByteArray());

    }

можно ли обрабатывать несколько файлов?

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...