How to upload a file as multipart form data to a lambda for processing ?

0

I have an HTTP API in API Gateway that calls to a lambda function to process a file. As of now I have followed below steps to achieve this.

  1. Created a lambda function for file processing.
  2. Created an API proxying the lambda in 1. Since lambda proxy integration is used lambda function receives the file as a base64 encoded string in the event body.
  3. Inside the lambda I decode the body content, apply required processing and send the result back.

I need to know whether there is an easier way to do this without having to decode the file content inside the lambda ? Like in normal JAVA rest application we receive the multipart content as an input stream.

1回答
1
承認された回答

Lambda receives a JSON event object, as such, you must encode binary data before including it in the JSON and passing it to Lambda.

profile pictureAWS
エキスパート
Uri
回答済み 1年前
profile picture
エキスパート
レビュー済み 7ヶ月前
  • how can this be done because I am struggling with it. I have this script for API call:

    <script> document.getElementById('upload-form').addEventListener('submit', function(event) { event.preventDefault(); var formData = new FormData(); formData.append('image-file', document.getElementById('image-file').files[0]); formData.append('watermark-text', document.getElementById('watermark-text').value); formData.append('watermark-color', document.getElementById('watermark-color').value); formData.append('watermark-size', document.getElementById('watermark-size').value); var xhr = new XMLHttpRequest(); xhr.open('POST', 'https://564zhl19u2.execute-api.us-east-1.amazonaws.com/watermark'); xhr.onload = function() { if (xhr.status === 200) { var response = JSON.parse(xhr.responseText); document.getElementById('result').innerHTML = response.message; if (response.image_url) { var downloadLink = document.createElement('a'); downloadLink.href = response.image_url; downloadLink.innerHTML = 'Download Watermarked Image'; downloadLink.setAttribute('download', ''); document.getElementById('result').appendChild(downloadLink); } } }; xhr.send(formData);

ログインしていません。 ログイン 回答を投稿する。

優れた回答とは、質問に明確に答え、建設的なフィードバックを提供し、質問者の専門分野におけるスキルの向上を促すものです。

質問に答えるためのガイドライン

関連するコンテンツ