简体   繁体   English

直接到s3 /客户端文件上传。 使用这种方法是否需要将未使用的文件存储在s3存储桶中?

[英]Direct to s3 / client file uploads. Is there a concern for storing unused files in your s3 bucket with this approach?

I was looking over this tutorial suggested by heroku (for NodeJs apps) for signing the s3 file via the server, then handling the upload directly from the client: 我正在查看heroku建议的本教程(对于NodeJs应用程序),该教程用于通过服务器对s3文件进行签名,然后直接从客户端处理上载:

https://devcenter.heroku.com/articles/s3-upload-node https://devcenter.heroku.com/articles/s3-upload-node

I wonder about the potential of many unused files being stored in your s3 bucket. 我想知道在您的s3存储桶中存储许多未使用文件的可能性。

In the heroku tutorial, they run through a user-edit scenario. 在heroku教程中,它们贯穿用户编辑场景。 They state : 他们说:

  • When a user selects an image to be uploaded, the upload to S3 is handled automatically and asynchronously with the process described earlier in this article. 当用户选择要上载的图像时,通过本文前面介绍的过程自动并异步地处理到S3的上载。 The image preview is then updated with the selected image once the upload is complete and successful. 上传成功且成功完成后,便会使用所选图像更新图像预览。

  • The user then clicks the “submit” button, which posts the username, name and the URL of the uploaded image to the Node application to be checked and/or stored. 然后,用户单击“提交”按钮,该按钮将用户名,名称和上载图像的URL发布到要检查和/或存储的Node应用程序。 If no image was uploaded by the user earlier the default avatar image URL is posted instead. 如果用户之前未上传任何图像,则会发布默认的头像图像URL。

So, what if the user selects the image, then clicks to another page without finishing and submitting the user-profile information? 那么,如果用户选择图像,然后单击另一个页面而不完成并提交用户配置文件信息,该怎么办?

Is that just a wasted file stored in your s3 bucket? 那仅仅是浪费的文件存储在您的s3存储桶中吗?


I"m using a similar approach in my MEAN app, where on submit: 我在MEAN应用中使用了类似的方法,请在以下位置提交:

  • I upload the file to S3. 我将文件上传到S3。

  • Then, with a promise, once the upload completes, I submit the user's profile information / post with the s3 url to the server. 然后,带着诺言,一旦上传完成,我将用户的个人资料信息/带有s3网址的帖子提交到服务器。

I had a similar concern, what if the user leaves before the promise invokes or there is a connection issue -- is there a concern of storing unused files? 我有一个类似的问题,如果用户在promise调用之前离开或存在连接问题,该怎么办?是否存在存储未使用文件的问题?

Is this the typical way of handling this, and that's just part of the risk? 这是处理此问题的典型方法,那只是风险的一部分?

The fact that the upload is occurring client side doesn't make this problem any more or less worse than if you did it server side. 上载发生在客户端的事实并没有使这个问题比起您在服务器端进行的那样严重。 You still need a mechanism of handling errors and keeping things in sync with your database. 您仍然需要一种机制来处理错误并使事物与数据库保持同步。

How you handle this depends on your specific application needs. 如何处理取决于您的特定应用程序需求。 @ceejayoz mentioned one method of having a temporary bucket. @ceejayoz提到了一种拥有临时存储桶的方法。 I prefer to not worry about the upload until it's done, handling the data update with a Lambda job. 我宁愿不要担心上传完成后再使用Lambda作业处理数据更新。 You could also have a sync process with list operations if you really wanted to, but I think that's typically unnecessary. 如果确实需要,也可以使用列表操作进行同步处理,但是我认为通常没有必要。

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

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