亚马逊、AWS、图像和 Carrierwave - 一切正常但无法上传
Amazon, AWS, images and Carrierwave - everything working but no upload
到目前为止,我一直在努力使它在我的一生中发挥作用。
到达以下阶段:
React 在 formData 中发送图像。
我的公司模型有一个 company_logo 上传器。
图像似乎附加成功。
公司保存成功。
但是:
在 company_logo 字段中,它只是文件的名称...
AWS里面什么都没有。
有没有人有什么想法?
company.company_logo = params['companylogo']
=> #<ActionDispatch::Http::UploadedFile:0x00007f92ca3371b0
@content_type="image/jpeg",
@headers=
"Content-Disposition: form-data; name=\"companylogo\"; filename=\"TP-Twitter-Profile.jpg\"\r\nContent-Type: image/jpeg\r\n",
@original_filename="TP-Twitter-Profile.jpg",
@tempfile=#<File:/var/folders/cg/4d0655v10j9_zzkkclng3ch00000gn/T/RackMultipart20181003-74913-1cgb17m.jpg>>
[4] pry(#<NewController>)> company
=> #<Company:0x00007f92cc881060
id: nil,
name: "sdkljfjklsdf",
pod_id: 9,
officelocation: nil,
created_at: nil,
updated_at: nil,
campaign_link: nil,
company_logo: nil>
[5] pry(#<NewController>)> company.company_logo
=> #<CompanyLogoUploader:0x00007f92c6862aa8
@cache_id="1538555179-74913-0001-2710",
@cache_storage=
#<CarrierWave::Storage::File:0x00007f92c6860708
@cache_called=nil,
@uploader=#<CompanyLogoUploader:0x00007f92c6862aa8 ...>>,
@file=
#<CarrierWave::SanitizedFile:0x00007f92c68619c8
@content=nil,
@content_type="image/jpeg",
@file="/Users/paulharker/projects/tpdb/tmp/uploads/1538555179-74913-0001-2710/TP-Twitter-Profile.jpg",
@original_filename="TP-Twitter-Profile.jpg">,
@filename="TP-Twitter-Profile.jpg",
@model=
#<Company:0x00007f92cc881060
id: nil,
name: "sdkljfjklsdf",
pod_id: 9,
officelocation: nil,
created_at: nil,
updated_at: nil,
campaign_link: nil,
company_logo: nil>,
@mounted_as=:company_logo,
@original_filename="TP-Twitter-Profile.jpg",
@versions={}>
[6] pry(#<NewController>)> company.save!
(0.2ms) BEGIN
↳ (pry):8
Company Create (0.7ms) INSERT INTO "companies" ("name", "pod_id", "created_at", "updated_at", "company_logo") VALUES (, , , , ) RETURNING "id" [["name", "sdkljfjklsdf"], ["pod_id", 9], ["created_at", "2018-10-03 08:26:53.929667"], ["updated_at", "2018-10-03 08:26:53.929667"], ["company_logo", "TP-Twitter-Profile.jpg"]]
↳ (pry):8
(5.5ms) COMMIT
↳ (pry):8
=> true
和我的 carrierwave.rb 初始值设定项...
CarrierWave.configure do |config|
config.fog_provider = 'fog/aws'
config.fog_credentials = {
provider: 'AWS',
aws_access_key_id: ENV['AWS_ACCESS_KEY'],
aws_secret_access_key: ENV['AWS_SECRET'],
region: 'eu-west-2'
}
config.storage = :fog
config.fog_directory = 'images' # bucket name
config.cache_dir = "#{Rails.root}/tmp/uploads" # To let CarrierWave work on heroku
end
正如 kiddorails 在上面的对话中指出的那样,您需要将 storage :fog
添加到上传器中,而不是在初始化程序中。
Link 了解更多信息:
github.com/carrierwaveuploader/carrierwave#using-amazon-s3
到目前为止,我一直在努力使它在我的一生中发挥作用。
到达以下阶段:
React 在 formData 中发送图像。 我的公司模型有一个 company_logo 上传器。 图像似乎附加成功。 公司保存成功。
但是: 在 company_logo 字段中,它只是文件的名称... AWS里面什么都没有。
有没有人有什么想法?
company.company_logo = params['companylogo']
=> #<ActionDispatch::Http::UploadedFile:0x00007f92ca3371b0
@content_type="image/jpeg",
@headers=
"Content-Disposition: form-data; name=\"companylogo\"; filename=\"TP-Twitter-Profile.jpg\"\r\nContent-Type: image/jpeg\r\n",
@original_filename="TP-Twitter-Profile.jpg",
@tempfile=#<File:/var/folders/cg/4d0655v10j9_zzkkclng3ch00000gn/T/RackMultipart20181003-74913-1cgb17m.jpg>>
[4] pry(#<NewController>)> company
=> #<Company:0x00007f92cc881060
id: nil,
name: "sdkljfjklsdf",
pod_id: 9,
officelocation: nil,
created_at: nil,
updated_at: nil,
campaign_link: nil,
company_logo: nil>
[5] pry(#<NewController>)> company.company_logo
=> #<CompanyLogoUploader:0x00007f92c6862aa8
@cache_id="1538555179-74913-0001-2710",
@cache_storage=
#<CarrierWave::Storage::File:0x00007f92c6860708
@cache_called=nil,
@uploader=#<CompanyLogoUploader:0x00007f92c6862aa8 ...>>,
@file=
#<CarrierWave::SanitizedFile:0x00007f92c68619c8
@content=nil,
@content_type="image/jpeg",
@file="/Users/paulharker/projects/tpdb/tmp/uploads/1538555179-74913-0001-2710/TP-Twitter-Profile.jpg",
@original_filename="TP-Twitter-Profile.jpg">,
@filename="TP-Twitter-Profile.jpg",
@model=
#<Company:0x00007f92cc881060
id: nil,
name: "sdkljfjklsdf",
pod_id: 9,
officelocation: nil,
created_at: nil,
updated_at: nil,
campaign_link: nil,
company_logo: nil>,
@mounted_as=:company_logo,
@original_filename="TP-Twitter-Profile.jpg",
@versions={}>
[6] pry(#<NewController>)> company.save!
(0.2ms) BEGIN
↳ (pry):8
Company Create (0.7ms) INSERT INTO "companies" ("name", "pod_id", "created_at", "updated_at", "company_logo") VALUES (, , , , ) RETURNING "id" [["name", "sdkljfjklsdf"], ["pod_id", 9], ["created_at", "2018-10-03 08:26:53.929667"], ["updated_at", "2018-10-03 08:26:53.929667"], ["company_logo", "TP-Twitter-Profile.jpg"]]
↳ (pry):8
(5.5ms) COMMIT
↳ (pry):8
=> true
和我的 carrierwave.rb 初始值设定项...
CarrierWave.configure do |config|
config.fog_provider = 'fog/aws'
config.fog_credentials = {
provider: 'AWS',
aws_access_key_id: ENV['AWS_ACCESS_KEY'],
aws_secret_access_key: ENV['AWS_SECRET'],
region: 'eu-west-2'
}
config.storage = :fog
config.fog_directory = 'images' # bucket name
config.cache_dir = "#{Rails.root}/tmp/uploads" # To let CarrierWave work on heroku
end
正如 kiddorails 在上面的对话中指出的那样,您需要将 storage :fog
添加到上传器中,而不是在初始化程序中。
Link 了解更多信息: github.com/carrierwaveuploader/carrierwave#using-amazon-s3