gpt4 book ai didi

ruby-on-rails - Ruby on Rails - 是否可以通过/app/assets/images 中的表单保存图像?

转载 作者:行者123 更新时间:2023-12-05 00:13:03 24 4
gpt4 key购买 nike

我正在为一家销售二手车的小商店开发一个小型 Rub​​y on Rails 应用程序。该站点包含一个包含所有可用汽车的列表,其中包括汽车的图像。商店里最多有 20 辆车。

我读到将图像直接保存在数据库中不是最佳做法,最好使用 Amazon Web Services 等云存储服务存储文件,但我认为小型网站不需要这样的服务一次最多可显示 20 张图像。

我的想法是将图像保存在 /app/assets/images .员工将通过表格上传汽车的信息和图像。是否可以在文件夹中上传和保存图片/app/assets/images通过 Rails 中的表单?

最佳答案

As @Sergio already mentioned about assets folder and AWS S3 service.



AWS 很好,但仅限于 1 年免费套餐和最多 5GB。

云图像存储的替代解决方案是 Cloudinary .终身免费 <10GB,包括带宽, Link: How to use in Rails samples

Cloudinary 还在幕后使用 AWS(S3) 服务!
#Gemfile
gem 'cloudinary'
gem 'carrierwave'


# config/initializers/cloudinary.rb, if not exist create the file
# make sure to fill api keys!!!
Cloudinary.config do |config|
config.cloud_name = ....
config.api_key = ....
config.api_secret = ....
config.cdn_subdomain = false
end


# model/image.rb in my case.
class Image < ActiveRecord::Base
mount_uploader :image, ImageUploader
end


# app/uploaders/image_uploader.rb
class ImageUploader < CarrierWave::Uploader::Base

include CarrierWave::MiniMagick
include CarrierWave::ImageOptimizer
include Cloudinary::CarrierWave

process :convert => 'png'
# process :tags => ['team_registration']
# process :resize_to_fill => [300, 300, :north]

def store_dir
# "images/#{model.class.to_s.underscore}/#{model.team_name}"
"images/car_images/"
end

def public_id
"yr_domain_name_here/car_images/#{model.team_name}"
end

def cache_dir
"/tmp/cache/#{model.class.to_s.underscore}"
end

def filename
"#{model.team_name}_#{model.game.title}" + ".png" if original_filename.present?
end

def content_type_whitelist
/image\//
end

def extension_white_list
%w(jpg jpeg gif png)
end

end

关于ruby-on-rails - Ruby on Rails - 是否可以通过/app/assets/images 中的表单保存图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49319992/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com