简体   繁体   English

AWS lambda function:put事件未在PHP中直接浏览器上传中触发

[英]AWS lambda function:put event is not triggered in direct browser upload in php

I've successfully created a lambda function that resizes an image and stores into a bucket in s3(bucket name: cropped ). 我已经成功创建了一个lambda函数,该函数可以调整图像大小并存储到s3中的存储桶中(存储桶名称: cropped )。 Also this lambda function invokes when a file is uploaded into another bucket(bucket name: source ). 当文件上传到另一个存储桶(存储桶名称: source )时,此lambda函数也会调用。

When i upload an image through aws console into the source bucket the AWS lambda function is triggered and the cropped image is created in cropped bucket. 当我通过AWS控制台将图像上传到source存储桶时,将触发AWS lambda函数,并在cropped存储桶中创建裁剪的图像。

But when i try with programmatic file upload ( s3 browser file upload) the lambda function is not triggered(cropped image is not creating in cropped bucket) however the image is successfully uploaded into source bucket. 但是当我尝试使用程序文件上传(s3浏览器文件上传)时,lambda函数未触发(裁剪的镜像中未创建cropped的图像),但是图像已成功上传到source存储桶中。

Browser file upload 浏览器文件上传

<form id="upload" action="//s3-us-west-2.amazonaws.com/lambdacushbu" method="POST" enctype="multipart/form-data">

    <input type="hidden" name="Content-Type" value="multipart/form-data" />
<input type="hidden" name="acl" value="private" />
<input type="hidden" name="success_action_status" value="201" />
<input type="hidden" name="policy" value="eyJleHBpcmF0aW9uIjoiMjAxNy0wMy0yNFQxMTo0NDoxMFoiLCJjb25kaXRpb25zIjpbeyJidWNrZXQiOiJsYW1iZGFjdXNoYnUifSx7ImFjbCI6InByaXZhdGUifSxbInN0YXJ0cy13aXRoIiwiJGtleSIsIiJdLFsiZXEiLCIkQ29udGVudC1UeXBlIiwibXVsdGlwYXJ0XC9mb3JtLWRhdGEiXSxbImNvbnRlbnQtbGVuZ3RoLXJhbmdlIiwwLDUyNDI4ODAwMF0seyJzdWNjZXNzX2FjdGlvbl9zdGF0dXMiOiIyMDEifSx7IngtYW16LWNyZWRlbnRpYWwiOiJBS0lBSlJWRVhVVFRWTjROWUFSUVwvMjAxNzAzMjRcL3VzLXdlc3QtMlwvczNcL2F3czRfcmVxdWVzdCJ9LHsieC1hbXotYWxnb3JpdGhtIjoiQVdTNC1ITUFDLVNIQTI1NiJ9LHsieC1hbXotZGF0ZSI6IjIwMTcwMzI0VDA1NDQxMFoifV19" />
<input type="hidden" name="X-amz-credential" value="AKIAJRVEARQ/20170324/us-west-2/s3/aws4_request" />
<input type="hidden" name="X-amz-algorithm" value="AWS4-HMAC-SHA256" />
<input type="hidden" name="X-amz-date" value="20170324T054410Z" />
<input type="hidden" name="X-amz-signature" value="854ea7ec0c456c03509d22a6de39b045e54b71a779af8d88175717d8b54ccebc" />
<input type="hidden" name="key" value="${filename}" />
    <input type="file" name="file" id="image">
    <br>
    <input type="submit" value="upload" name="upload">
        <span id="status-text"></span>
        <img src=""  id="cropped-image">
</form>

UPDATE UPDATE

I've tried with normal file upload method ie user uploads file to my server and then it put into aws s3 bucket. 我尝试使用正常的文件上传方法,即用户将文件上传到我的服务器,然后将其放入AWS s3存储桶。 Now its working 现在工作了

So i think there is an issue with direct browser upload 所以我认为浏览器直接上传存在问题

Finally i resolved the issue for the browser direct uploads the events is POST 最后我解决了浏览器直接上传事件是POST

For enabling 启用

1.Go to s3 console and select the bucket. 1.转到s3控制台并选择存储桶。

2.Go to properties select Events and add a new event with POST 2.转到属性选择事件并使用POST添加新事件

Create the event with post and choose your lambda function that you want to invoke and save. 使用post创建事件,然后选择要调用并保存的lambda函数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM