简体   繁体   English

Rails在carrierwave中查找存储文件本地URL

[英]Rails Finding the storing file local URL in carrierwave

Working on a project that use a gem named OcrSpace to perform ocr on image uploaded by carrierwave . 正在使用一个名为OcrSpace的gem在载波上上传的图像上执行ocr的项目。

After a button is clicked, the text in the image would be shown in the website. 单击按钮后,图像中的文本将显示在网站上。

Here's the code: 这是代码:

<%= image_tag( @resume.attachment_url) %>
<div id="cool"> </div>


<button onclick="myFunction()">Try it</button>

<% require 'ocr_space' resource = OcrSpace::Resource.new(apikey: "xxxxxxxxx") %>

<% result = resource.clean_convert file: @resume.attachment_url %>

<script>
function myFunction() {
    document.getElementById("cool").innerHTML = <%= result %>;
}
</script>

However, I got this error 但是,我得到了这个错误

No such file or directory @ rb_sysopen - /uploads/resume/attachment/3/_____2018-07-19___9.15.42.jpg 没有这样的文件或目录@ rb_sysopen-/uploads/resume/attachment/3/_____2018-07-19___9.15.42.jpg

It seems that the file path is incorrect 似乎文件路径不正确

Can anyone help me, thanks. 谁能帮我,谢谢。

use 采用

@resume.attachment.path @ resume.attachment.path

instead of @resume.attachment_url 而不是@ resume.attachment_url

url will not give you a local path to open as a file 网址不会为您提供以文件形式打开的本地路径

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

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