简体   繁体   English

逐步加载由 Lambda function 生成的 AWS S3 文件

[英]Gradually loading AWS S3 files generated by Lambda function

I have a site where the user can upload an image.我有一个用户可以上传图片的网站。 The image is uploaded to an S3 bucket, then processed with a Lambda function that generates 7 different coloured versions of the image, stores them on an S3 bucket and the function ultimately returns the URLs of the new coloured images back to the user so they can select their preferred color on the site.图像上传到 S3 存储桶,然后使用 Lambda function 进行处理,生成 7 种不同颜色版本的图像,将它们存储在 S3 存储桶中,ZC1C425268E68385D1AB5074C17A94F1 最终返回给用户,因此他们可以将新的彩色图像返回给用户select 他们在网站上的首选颜色。

This process takes some time, around 5-6 seconds with a good connection, during which the user can only see a loading screen.这个过程需要一些时间,在连接良好的情况下大约需要 5-6 秒,在此期间用户只能看到加载屏幕。 Since it's only possible with one callback from lambda, how would I go about to "lazy load" the 7 different coloured images rather than having the loading screen?由于只能通过 lambda 的一次回调,我将如何 go 将“延迟加载”7 个不同的彩色图像而不是加载屏幕? I would like to have something like a skeleton UI which gradually loads the different coloured images as soon as each of them are generated, rather than having to wait for all of them.我想要一个类似于骨架 UI 的东西,它会在生成每个图像后逐渐加载不同颜色的图像,而不必等待所有图像。 Is this possible?这可能吗?

A better approach might be to return the URLs immediately , before the images are actually generated, because the target URLs will be known.更好的方法可能是在实际生成图像之前立即返回 URL,因为目标 URL 是已知的。 This could be done by having the Lambda function invoke another Lambda to do the actual processing, and then return the URL immediately.这可以通过让 Lambda function 调用另一个 Lambda 来进行实际处理来完成,然后立即返回 ZE6B391A23D2C4D45702A366。

Then, the web app could try to retrieve the images every few seconds.然后,web 应用程序可以尝试每隔几秒检索一次图像。

You could even have the process spawn several Lambda processes in parallel to reduce the time taken to generate all the images (and/or try multi-threading the Lambda to see if that is any faster).您甚至可以让该进程并行生成多个 Lambda 进程,以减少生成所有图像所需的时间(和/或尝试对 Lambda 进行多线程处理以查看是否更快)。

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

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