我的应用程序无法从服务器加载一些图像 [英] My app cannot load some images from the server

查看:173
本文介绍了我的应用程序无法从服务器加载一些图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在本地WEBrick服务器上使用Ruby on Rails。



我正在从网址生成一些网站的图片,将它们写入我的本地文件系统,展示他们。我通过他们的网址命名图像,但用 - 替换所有 \ 。有些图像似乎没有加载,因为它找不到我的文件系统上的图像,我得到破碎的图像图标。但是,当我查看我的文件系统时,我看到所有的图像都在那里。



这是我在日志中收到的错误:

 开始GET/images/image_site/http:--www.urbandictionary.com-define.php?term=slim%20shady.jpg?1309465379为127.0。 0.1在Thu Jun 30 13:23:06 -0700 2011 

ActionController :: RoutingError(没有路线匹配/images/image_site/http:--www.urbandictionary.com-define.php) :

这是我的html代码:

 < img alt =Http: -  www.urbandictionary.com-define.php?term = slim%20shadyclass =site_imagesrc =/ images / image_site / http : -  www.urbandictionary.com-define.php?term = slim%20shady.jpg?1309465379> 

发生了什么,我该如何解决?如果我需要提供更多信息,请让我知道。

解决方案

看起来你没有正确编码你的图像名称 src 属性。我猜想你有一个这样的名字的文件:

  http: -  www.urbandictionary.com-define .php?term = slim%20shady.jpg 

但是当你有这个的时候:

  src =/ images / image_site / http: -  www.urbandictionary.com-define.php?term = slim%20shady.jpg?1309465379 

文件名如下所示:

  / images / image_site / http: -  www.urbandictionary.com-define.php 

,因为第一个之后的所有内容都被视为查询字符串的一部分。



用连字符替换斜线不够好,你仍然会留下各种各样的漏洞,造成混乱和恶意。相反,您应该完全生成图像文件名称,像 id.jpg 其中 id 是您图像的ID数据库。然后,将原始的文件名存储在数据库中,并且只向用户显示文件名(正确编码!),不要在本地文件系统中使用。



修复将是正确的URL编码您的 src 属性。但你真的应该解决你如何处理图像,否则你会让自己开放到各种各样的麻烦。


I'm using Ruby on Rails on my local WEBrick server.

I'm generating some images of websites from urls, writing them to my local filesystem, and displaying them. I name the images by their url but replace all \ with -. Some images seem to not be loading because it cannot find the images on my filesystem, and I get the broken image icon. However, I see that all the images are there when I check my filesystem.

This is the error I get in my logs:

Started GET "/images/image_site/http:--www.urbandictionary.com-define.php?term=slim%20shady.jpg?1309465379" for 127.0.0.1 at Thu Jun 30 13:23:06 -0700 2011

ActionController::RoutingError (No route matches "/images/image_site/http:--www.urbandictionary.com-define.php"):

This is my html code:

<img alt="Http:--www.urbandictionary.com-define.php?term=slim%20shady" class="site_image" src="/images/image_site/http:--www.urbandictionary.com-define.php?term=slim%20shady.jpg?1309465379">

What going on and how can I fix this? Please let me know if I need to provide more information.

解决方案

Looks like you're not properly encoding your image names in the src attribute. I'd guess that you have a file with a name like this:

http:--www.urbandictionary.com-define.php?term=slim%20shady.jpg

But when you have this:

src="/images/image_site/http:--www.urbandictionary.com-define.php?term=slim%20shady.jpg?1309465379"

The filename looks like this:

/images/image_site/http:--www.urbandictionary.com-define.php

because everything after the first ? is considered to be part of the query string.

Replacing the slashes with hyphens is not good enough, you're still leaving all sorts of holes for confusion and nefarious intent. Instead, you should generate the image file names completely, something like id.jpg where id is the image's ID in your database. Then, store the original filename in your database and only show that filename (properly encoded!) to people, don't use it in your local file system.

A quick fix would be to properly URL encode your src attributes. But you really should fix up how you handle the images or you will leave yourself open to all sorts of trouble.

这篇关于我的应用程序无法从服务器加载一些图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆