Rails 代理控制器未正确拉取图像,如何适当修改?

编程入门 行业动态 更新时间:2024-10-28 12:31:01
本文介绍了Rails 代理控制器未正确拉取图像,如何适当修改?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我必须在 Rails 3.1 应用程序上实现代理以解决一些跨域 JS 问题.

I'm having to implement a proxy on a Rails 3.1 app to overcome some cross-domain JS issues.

到目前为止,我检索网页文本源似乎是正确的,但是它通常会丢失页面中的图像(可能是相对路径?),然后当我使用绝对路径指向图像时,它将显示 图像的ascii编码而不是图像本身,我认为出于熟悉的人的代码的明显原因与主题.

So far I have it retrieving web page text source seemingly right, however it commonly misses images (perhaps relative paths?) in the page and then when I direct it with an absolute path to an image it will show the ascii encoding of the image rather than the image itself, I think for obvious reasons from the code for someone familiar with the topic.

我希望有人能够修改以下代码,以便在图像代理情况下也能正常工作:

I was hopeful that someone would be able to revise the following code so as to work also properly with an image proxy situation:

proxy_controller.rb:

class ProxyController < ApplicationController def get url = URI.parse(params["url"]) result = Net::HTTP.get_response(url) render :text => result.body end end

routes.rb:

get "proxy" => "proxy#get", :as => "proxy"

通过以下方式调用:

<my_dev_server>/proxy?url=<somedomain.tld>/path/to/page/images/image.jpg

<my_dev_server>/proxy?url=<somedomain.tld>/path/to/page

推荐答案

使用send_data

更多推荐

Rails 代理控制器未正确拉取图像,如何适当修改?

本文发布于:2023-10-26 10:50:41,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1529917.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:控制器   图像   正确   Rails

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!