简体   繁体   English

blueimp jQuery-File-Upload在上传图像后不显示缩略图

[英]blueimp jQuery-File-Upload not displaying thumbnail after uploading the image

I have downloaded latest plugin and dependencies from here version 9.12.1. 我从这里的版本9.12.1下载了最新的插件和依赖项。

I copied the downloaded files in my wamp server and accessed it from localhost/jQuery-File-Upload-9.12.1/index.html . 我将下载的文件复制到我的wamp服务器中,并从localhost / jQuery-File-Upload-9.12.1 / index.html访问它。

After selecting image file, a preview of image is displayed before uploading. 选择图像文件后,在上传之前会显示图像预览。 But once image is uploaded the thumbnail is not getting displayed. 但是一旦上传图像,缩略图就不会显示出来。

However in Inspect Element the link of thumbnail is present in image src. 但是在Inspect Element中,缩略图的链接出现在图像src中。

在此输入图像描述

File is uploaded in server folder and thumbnail is created. 文件上传到服务器文件夹并创建缩略图。

在此输入图像描述

Name and size of image is getting displayed. 显示图像的名称和大小。 在此输入图像描述

What am I doing wrong ? 我究竟做错了什么 ?

Making with dirty tricks ... loop until the image is ready before showing preview image. 使用肮脏的技巧...循环,直到图像准备就绪,然后显示预览图像。
See jQuery: Check if image exists . 请参阅jQuery:检查图像是否存在 In my case I use before the image tag as ... 在我的情况下,我在图像标记之前使用...

            while(urlExists(file.path) != 200) {
                   console.log("still loading image");
            }
            <img src="=file.path" width="100px">

The problem is writing image is a little late than response to client. 问题是写图像比响应客户端要迟一点。 So , 404 error for this image after rendering to html. 因此,渲染到html后,此图像出现404错误。 But image is actually exist when I checked. 但是当我检查时,图像实际存在。 As above snippet ,I am trying to wait for loading image after server has successfully created image. 如上面的代码片段,我试图在服务器成功创建图像后等待加载图像。 I know it is not a good way but it works. 我知道这不是一个好方法,但它有效。 I believe this error will not happen at production mode and I am trying to fix for running at localhost. 我相信在生产模式下不会发生此错误,我正在尝试修复在localhost上运行。

As per your question and comments, check for two things: 根据您的问题和评论,检查两件事:

First, the thumbnail image downloaded has status 200 or 404 in network tab of developer window. 首先,下载的缩略图图像在开发者窗口的网络选项卡中具有状态200或404。 If its 200, issue is something else. 如果它的200,问题是别的。

If it is 404: Check in your .htaccess file for this content: 如果是404:请在.htaccess文件中检查此内容:

RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?yourdomain.com/.*$ [NC]
RewriteRule \.(gif|jpg|css)$ - [F]

The above lines tell the Apache Web Server to block all links to '.gif', '.jpg' and '.css' files which are not from the domain name ' http://www.yourdomain.com/ '. 以上几行告诉Apache Web Server阻止所有链接到'.gif','.jpg'和'.css'文件,这些文件不是来自域名' http://www.yourdomain.com/ '。 Before uploading your .htaccess file ensure you replace 'yourdomain.com' with the appropriate web site address. 在上传.htaccess文件之前,请确保将“yourdomain.com”替换为相应的网站地址。

See if the url in .htaccess is properly set to your domain (ie, localhost). 查看.htaccess中的url是否已正确设置到您的域(即localhost)。

Reference: http://www.htaccess-guide.com/hot-link-prevention-techniques/ 参考: http//www.htaccess-guide.com/hot-link-prevention-techniques/

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

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