如何在亚马逊s3 Paperclip中复制文件?

时间:2016-01-07 17:31:34

标签: ruby-on-rails amazon-s3 paperclip aws-sdk

我的模型Shop有一个logo,它存储在亚马逊s3中,我想将它复制到另一个模型Company,我只是这样做:

shop = Shop.find(1)
company = Company.find(1)
company.logo = shop.logo
company.save!

但它给出了一个错误:

[paperclip] copying logos/1/original/220px-Bart_Simpson.png to local file /tmp/dac9e3329951078b23c5deed39f3193120160107-30855-ivrdms.png
No Such Key - cannot copy logos/1/original/220px-Bart_Simpson.png to local file /tmp/dac9e3329951078b23c5deed39f3193120160107-30855-ivrdms.png
Command :: file -b --mime '/tmp/dac9e3329951078b23c5deed39f3193120160107-30855-nz0h5c.png'
[paperclip] Content Type Spoof: Filename 220px-Bart_Simpson.png (["image/png"]), content type discovered from file command: inode/x-empty. See documentation to allow this combination.

ROLLBACK
ActiveRecord::RecordInvalid: Validation failed: Logo has an extension that does not match its contents

有人可以说这到底是怎么回事,或者怎么做?

1 个答案:

答案 0 :(得分:0)

你可以尝试,我可以知道正在使用哪个版本的回形针。

shop = Shop.find(1)
company = Company.find(1)
company.logo = File.open(shop.logo.path, 'rb')
company.save!