问题网址为缩略创造了使用社插在轨道上6

0

的问题

我一直在努力与这几天,并希望有人可以帮助。 可能有一些明显的是,我见了!

我使用的社插件轨道上载PDF文件和产生的缩略为第一页。 PDF被装载在指定的存储空间和缩略也越来越创造和获得排序相同的位置。 但是我不能够显示的略图。

初始化程序:

require "shrine"
require "shrine/storage/file_system"
#require "shrine/storage/memory"

Shrine.storages = {
    cache: Shrine::Storage::FileSystem.new("public", prefix: "uploads/cache"),
    store: Shrine::Storage::FileSystem.new("public", prefix: "uploads/store")
}

Shrine.plugin :activerecord    # loads Active Record integration
Shrine.plugin :cached_attachment_data # enables retaining cached file across form redisplays
Shrine.plugin :restore_cached_data  # extracts metadata for assigned cached files
Shrine.plugin :determine_mime_type
Shrine.plugin :validation_helpers
Shrine.plugin :validation
Shrine.plugin :derivatives
#Shrine.plugin :model, cache: false

上传:

require "image_processing/mini_magick"

class FileUploader < Shrine
 include ImageProcessing::MiniMagick

 plugin :processing # allows hooking into promoting
 plugin :versions   # enable Shrine to handle a hash of files
 plugin :derivatives
 plugin :default_url
# plugin :delete_raw # delete processed files after uploading

 Attacher.validate do
  validate_max_size 5*1024*1024, message: "is too large (max is 5 MB)"
  validate_mime_type %w[application/pdf]
 end

 Attacher.derivatives do |original|
  magick = ImageProcessing::MiniMagick.source(original).loader(page:0).convert("jpeg")
  {
   thumb: magick.resize_to_limit!(200, 200) 
  }

 end

end

检查看:

<p id="notice"><%= notice %></p>

<p>
  <strong>Number:</strong>
  <%= @issue.number %>
</p>

<p>
  <strong>Title:</strong>
  <%= @issue.title %>
</p>

<p>
  <strong>Data:</strong>
  <%= @issue.file_data %>
</p>

<p>
  <strong>Issue Preview</strong>
  <embed src="<%= @issue.file_url %>" width="80" height="160" />
</p>

<p>
  <strong>Issue Thumbnail:</strong>
  <%= image_tag @issue.file_url(:thumb) if @issue.file %>
</p>

<p>
  <strong>Issue:</strong>
  <%= image_tag @issue.file_url if @issue.file %>
</p>

<%= link_to 'Edit', edit_issue_path(@issue) %> |
<%= link_to 'Back', issues_path %>

此外,当我看看数据存储在file_data场我看没有任何信息添加的略图。

文件数据:{"id":"fccd20a9323aa5b63fd912f4ca833ebb.pdf","storage":"store","metadata":{"filename":"pdf_sample.pdf","size":351987,"mime_type":"application/pdf"}}

pdf ruby-on-rails shrine thumbnails
2021-11-20 21:41:41
2
0

你需要启用自动建立在附件促进永久性存储:

Shrine.plugin :derivatives, create_on_promote: true

或处理的衍生物的手上,附件:

record.file_derivatives!
2021-11-21 19:40:25

谢谢你对你的快速反应。 我有试图处理的衍生物这两种方式你的上述建议和缩略得到创造和sored沿用pdf格式的附件而不是一个问题。 我也可以打电话访问该网址的文件我看过@问题。file_url. 唯一的事情是不能工作对我来说是的URL缩略@问题。file_url(:拇指). 数据的缩略也是不存在的file_data柱:{"id":"a94c1a6e31176ed530b786ef3cefe18a.pdf","storage":"store","metadata":{"filename":"comic_sample.pdf","size":351987,"mime_type":"application/pdf"}}.
user1851592

该衍生物数据的缺失,列装置的衍生物,是不是产生,这就是为什么该网址是为零。 因为你发表您的设置没有 create_on_promote: true 设置,而你没有显示创造衍生物明确,我认为,这根本不是叫。
janko-m

再次感谢你,生病看看我的设置。 快速的问题:如何缩略获得生成的,如果该类别.衍生物是不是被叫什么?
user1851592
0

终于想通了。 我解决了这一问题通过添加以下的_form.html。erb:

<%= form.hidden_field :image, value: @photo.cached_image_data %>
2021-12-08 23:46:19

其他语言

此页面有其他语言版本

Русский
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
한국어
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................