图像上传后,Paperclip 5.1.0 - Rails 5 - 缺失

时间:2017-01-15 07:56:26

标签: imagemagick windows-10 paperclip ruby-on-rails-5 ruby-2.3

如果我尝试上传图片信息,则显示:

"New Content
1 error prohibited this content from being saved:

That cover has contents are not what they are reported to be "

然后显示“缺失”

在Git Bash中出现:

"[Paperclip] Content Type Spoof: Filename goku.jpg (image / jpeg from Headers, [" image / jpeg "] from Extension), content type discovered from file command:. See documentation to allow this combination.
   (0.0ms) begin transaction
Command :: -b --mime file "C: /Users/xxxxxx/AppData/Local/Temp/1151fe66500e3084eef890162322a11020170115-9100-1xumnlr.jpg"
[Paperclip] Content Type Spoof: Filename juegos-vestir-goku.jpg (image / jpeg from Headers, [ "image / jpeg"] from Extension), content type discovered from file command:. See documentation to allow this combination.
   (0.0ms) rollback transaction
  Rendering contents / new.html.erb Within layouts / application
  Rendered contents / _form.html.erb (4.0ms)
  Rendered contents / new.html.erb Within layouts / application (30.0ms)
  Rendered layouts / _header2.html.erb (2.0ms)
  Rendered layouts / _footer.html.erb (0.0ms)
Completed 200 OK in 627ms (Views: 511.2ms | ActiveRecord: 0.0ms) "

当我安装paperclip时出现了消息:

"Post-install message from paperclip:
##################################################
# NOTES FOR UPGRADING FROM 4.3.0 OR EARLIER #
##################################################

Paperclip is now compatible with aws-sdk> = 2.0.0.

If you are using S3 storage, aws-sdk> = 2.0.0 requires you to make a few small
changes:

* You must September the `s3_region`
* If you are Explicitly setting permissions anywhere, such as in an initializer,
  notes That the format of the permissions changed from using an underscore to
  using a hyphen. For example, `: public_read` needs to be changed to
  `Public-read`.

For a walkthrough of upgrading from 4 to 5 and aws-sdk> = 2.0 you can watch
http://rubythursday.com/episodes/ruby-snack-27-upgrade-paperclip-and-aws-sdk-in-prep-for-rails-5 "

执行安装回形针的操作:

- Downloaded magemagick for windows
- Insert in Gemfile gem "paperclip", "~> 5.0.0"
- Bundle install

- In the app >> model >> content.rb I entered:
has_attached_file: cover, styles {medium: "300x>" thumb "100x>"}
validates_attachment_content_type: cover, content_type: /\Aimage\/.*\z/

- Rails generate paperclip content cover

- Rake db: migrate

- I added to my code in the app> views> contents> _form,:
 <%= form_for @content, html: { multipart: true } do |f| %>

<Div class = "field">
    <% = F.label: cover%>
    <% = F.file_field: cover%>
  </ Div>

- App> controllers> content, I entered:
def content_params
      params.require (: content) .permit (: title: description: price,: cover)
end

- App> views> content> show I entered:
<% = @ Image_tag content.cover.url (: thumb)%>

- App> views> content> index> I entered:
<Td> <% = image_tag content.cover.url (: medium)%> </ td>

使用的版本:

-Win10 x64
-ruby 2.3.3p222
-Rails 5.0.1
-paperclip 5.1.0

进行了测试,但没有果断:

  • 在应用中添加&gt;模型&GT; content.rb:

    :default_url =&gt; “/images/:style/missing.png”

  • 在config / environments / development.rb中添加:

    Paperclip.options [:command_path] =“/ usr / local / bin /”

    Paperclip.options [:command_path] ='C:\ Program Files(x86)\ GnuWin32 \ bin

  • 已添加 - 在应用中添加&gt;模型&GT; content.rb:

    Paperclip.options [:command_path] ='C:\ Program Files(x86)\ GnuWin32 \ bin; C:\ Program Files \ ImageMagick-7.0.4-Q16'

    Paperclip.options [:swallow_stderr] = false

0 个答案:

没有答案