如何使用神社获取照片缓存数据

我想在shropper js中使用神社的宝石, 我读了Shrine image cropping ,并参考了sample cods, 首先,我复制了示例代码,但是我发生了

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

我认为这个错误我无法发送正确的路径,我没有解决此错误,

有人可以帮助我吗?

application.js的一部分:

var uppy = Uppy.Core({
   autoProceed: true,restrictions: {
     allowedFileTypes: fileInput.accept.split(','),}
  })
  .use(Uppy.FileInput,{
   target: formGroup,locale: { strings: { chooseFiles: 'Choose file' } },})
 .use(Uppy.Informer,})
  .use(Uppy.ProgressBar,{
   target: imagePreview.parentNode,})
  .use(Uppy.ThumbnailGenerator,{
    thumbnailWidth: 600,})
  .use(Uppy.XHrupload,{
    endpoint: '/app/assets/images/uploads',})

  uppy.on('upload-success',(file,response) => {

  var uploadedFileData = JSON.stringify(response.body['data'])
  // set hidden field value to the uploaded file data so that it's submitted with the form as the attachment
console.log(response.uploadURL)

cropbox(imagePreview,response.uploadURL,{
  onCrop(detail) {
    let fileData = JSON.parse(uploadedFileData)
    fileData['metadata']['crop'] = detail
    hiddenInput.value = JSON.stringify(fileData)
  }
})
})

uppy.on('thumbnail:generated',preview) => {
  imagePreview.src = preview
})
}

form.html.erb:

 <div class="form-group">
  <%= f.fields_for :photos,@blog_form.get_photos do | photos_fields| %>

    <%= photos_fields.label :image %>

    <%= photos_fields.hidden_field :image,value: photos_fields.object.cached_image_data,class: "upload-data" %>

    <%= photos_fields.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 photos_fields.object.image_url(:medium),width: 300,class: "img-thumbnail file-upload-preview",id: "preview-photo" %>
 </div>


   <% end %>

routes.rb:

 Rails.application.routes.draw do

 mount ImageUploader.derivation_endpoint => "/derivations/image"
 mount ImageUploader.upload_endpoint(:cache) => "/app/assets/images/uploads"
 get "/derivations/image/*rest" => "derivations#image"


 get 'sessions/new'

 devise_for :users

 resources :users do

  resources :blogs

 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 :derivatives
plugin :upload_endpoint
plugin :derivation_endpoint,prefix: "/app/assets/images/uploads"

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

/uploads/cache/5a01d66280a502d7256acffeb1b21bca.jpeg
iCMS 回答:如何使用神社获取照片缓存数据

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

大家都在问