如何在Shrine中使用Upload Endpoint插件?

我想使用神社的宝石,我读了Shrine image cropping Shrine Upload Endpoint plugin,然后引用了sample codes, 首先,我复制了示例代码,但是我发生了

 actionController::RoutingError (No route matches [GET] " 
/uploads/cache/47eee6dc368f20db1e26fa5176552136.jpg"):

我认为此错误我无法发送正确的路径,我无法解决此错误,即我不能很好地使用Upload Endpoint插件,可以发送Post请求但不能使用get request

有人请教我如何在神社中使用获取请求?

form.html.erb:

<div class ="container">
 <div class ="row">
 <%= form_with model: @photo,url:   photos_new_path,local: true do |f| %>

  <div class="form-group">

  <%= f.label :image %>

  <%= f.hidden_field :image,value: @photo.cached_image_data,class: "upload-data" %>

  <%= f.file_field :image,accept: ImageUploader::ALLOWED_TYPES.join(","),data: {
  upload_server: "upload_server",preview_element: "preview-photo",upload_result_element: "preview-photo-upload-result",}%>

  <div class="image-preview">
  <!-- static link to the thumbnail generated on attachment -->
  <%= image_tag @photo.image_url.to_s,width: 300,class: "img-thumbnail file-upload-preview",id: "preview-photo" %>
 </div>

 </div>

 <%= f.submit "create",class: "btn btn-primary" %>

<% end %>
</div>

routes.rb:

 Rails.application.routes.draw do

 get 'photos/new'
 mount ImageUploader.upload_endpoint(:cache) => "/app/assets/images/uploads"
 mount ImageUploader.derivation_endpoint => "/derivations/image"
 mount ImageUploader.presign_endpoint(:cache) => "/images/presign"


 get 'sessions/new'

 devise_for :users

 resources :users do
  resources :photos 

 end
# For details on the DSL available within this file,see https://guides.rubyonrails.org/routing.html
end

Shrine.rb插件:

require "shrine"
require "shrine/storage/file_system"




Shrine.storages = {
 cache: Shrine::Storage::FileSystem.new("app/assets/images",prefix: "uploads/cache"),# temporary
 store: Shrine::Storage::FileSystem.new("app/assets/images",prefix: "uploads"),# permanent
}


Shrine.plugin :pretty_location
Shrine.plugin :determine_mime_type,analyzer: :marcel


Shrine.plugin :activerecord           # loads active Record integration
Shrine.plugin :cached_attachment_data # for retaining the cached file across form redisplays
Shrine.plugin :restore_cached_data # re-extract metadata when attaching a cached file

Shrine.plugin :validation_helpers


Shrine.plugin :derivatives
Shrine.plugin :derivation_endpoint,secret_key: "secret",expires_in: 10

Shrine.plugin :upload_endpoint,url: true
Shrine.plugin :default_url


 Shrine.plugin :backgrounding

Image_uploader.rb的插件:

plugin :store_dimensions,analyzer: :ruby_vips,log_subscriber: nil
plugin :derivatives

plugin :derivation_endpoint,prefix: "derivations/image"
plugin :presign_endpoint

我用console.log检查了路径,所以response.uploadURL是

/uploads/cache/47eee6dc368f20db1e26fa5176552136.jpg
iCMS 回答:如何在Shrine中使用Upload Endpoint插件?

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/2036196.html

大家都在问