简体   繁体   English

无法在Ruby on Rails中使用回形针上传图像

[英]Can't upload image with Paperclip in Ruby on Rails

I'm working on a simple api using ruby on rails, and tried to attach an image to my post but I always get this error: 我正在使用在Rails上使用ruby的简单api,并尝试将图像附加到我的帖子中,但是我总是会收到此错误:

"[paperclip] Link failed with File exists @ syserr_fail2_in - C:/Users/Safouene/AppData/Local/Temp/d5e01d9478f9774f9f669fd29da0cb2720190401-5260-1tjlj3v.png; copying link C:/Users/Safouene/AppData/Local/Temp/d5e01d9478f9774f9f669fd29da0cb2720190401-5260-ooex8h.png to C:/Users/Safouene/AppData/Local/Temp/d5e01d9478f9774f9f669fd29da0cb2720190401-5260-1tjlj3v.png Command :: file -b --mime "C:/Users/Safouene/AppData/Local/Temp/d5e01d9478f9774f9f669fd29da0cb2720190401-5260-1tjlj3v.png"" Completed 204 No Content in 65ms (ActiveRecord: 1.0ms) “ [回形针]链接失败,文件存在@ syserr_fail2_in-C:/Users/Safouene/AppData/Local/Temp/d5e01d9478f9774f9f669fd29da0cb2720190401-5260-1tjlj3v.png;复制链接C:/ Users / Safoue29 / f0d9df1-d9df1df1ddfdfdfdfdfdfdfdfdfdfdfdfdfdfdfdfdfdfdfdfdfdfdfdfd 5260-ooex8h.png到C:/Users/Safouene/AppData/Local/Temp/d5e01d9478f9774f9f669fd29da0cb2720190401-5260-1tjlj3v.png命令:: file -b --mime“ C:/ Users / Safouene / AppData / Local / Temp / d5e01040 -5260-1tjlj3v.png“”完成65毫秒内无内容204(ActiveRecord:1.0毫秒)

Here is My Model : 这是我的模特:

class Action < ApplicationRecord
  belongs_to :user 
  validates :title ,presence: true
  validates :desc ,presence: true 
  validates :location , presence: true 
  has_attached_file :picture 
  validates_attachment :picture, presence: true
  do_not_validate_attachment_file_type :picture
end

This is not strictly answering your question but I feel I should point out that since the release of active storage with rails 5.2 many of these file upload gems have been deprecated. 这并不是严格回答您的问题,但我认为我应该指出,自从发布带有Rails 5.2的活动存储以来,许多此类文件上载gem已被弃用。 This means they will no longer be maintained. 这意味着它们将不再被维护。 (see github page https://github.com/thoughtbot/paperclip ) (参见github页面https://github.com/thoughtbot/paperclip

With that in mind I would strongly advise you to use active storage, rather than paperclip. 考虑到这一点,我强烈建议您使用主动存储,而不是回形针。

Active storage is part of the rails core framework now so you can rest assured it will be maintained and always work the the latest releases of rails. 主动存储现在是Rails核心框架的一部分,因此您可以放心,它将得到维护,并始终使用最新版本的rails。

Plus, active storage is super easy to implement and full of really cool features. 此外,活动存储非常易于实现,并具有许多非常酷的功能。

You can read more about active storage here: https://edgeguides.rubyonrails.org/active_storage_overview.html 您可以在此处阅读有关活动存储的更多信息: https : //edgeguides.rubyonrails.org/active_storage_overview.html

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

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