简体   繁体   English

找不到Amazon S3映像。 必须推迟

[英]Amazon S3 Image not found. Have to put delay

I have a meteor app where I upload an image to S3 via a node framework called knox. 我有一个流星应用程序,在其中我通过称为knox的节点框架将图像上传到S3。

It works well but when Im getting the success response from S3 with the link to the image I also want to show it to the user like this: 它运行良好,但是当Im从S3获得成功响应并带有指向图像的链接时,我也想将其显示给用户:

$("#thumbnail").attr("src", url);

However this generates a 404 not found in the console and the image is not showing. 但是,这会生成在控制台中找不到的404,并且图像未显示。 But if I put a delay for around 5-10s it works. 但是,如果我延迟5到10秒钟左右,它就可以工作。

setTimeout(function() {
    $("#thumbnail").attr("src", url);
}, 10000);

Why do I get the URL from S3 before they are ready to show it? 为什么在他们准备显示S3之前从S3获得URL? Is there a way I can wait until its ready before showing it to the user? 有什么方法可以等它准备好再显示给用户吗?

As nodejs is asynchronous (meaning that it does not wait until one request is finished before next one gets called) your url gets returned quicker than the image is uploaded, therefor you can't see the image. 由于nodejs是异步的(意味着它不会等到一个请求完成才调用下一个请求),因此您的url返回的速度比上载图像的速度要快,因此您看不到该图像。 This could be fixed using callbacks. 这可以使用回调进行修复。

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

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