Tag: 载波

使用带有sinatra的ruby将video上传到Amazon S3

我正在构建一个Android应用程序,其后端写在ruby / sinatra上。 Android应用程序的数据以json数据的forms出现。 正在使用的数据库是mongodb。 我能够捕获后端的数据。 现在我要做的是上传一个在Android应用程序上以字节数组的forms发送的video。 我还想将video以字符串的forms存储在本地数据库中。 我一直在使用载波,雾和载波 – mongoidgem,但没有任何运气。 以下是我关注的一些博客: https://blog.engineyard.com/2011/a-gentle-introduction-to-carrierwave/ http://www.javahabit.com/2012/06/03/saving-files-in-amazon-s3-using-carrierwave-and-fog-gem/ 如果有人可以指导我如何专门与sinatra和mongodb一起解决这个问题,那就是我面临的主要问题。

如何正确地将record.image_integrity_error添加到现有条件?

历史: 如何与carrierwave结合有条件地显示状态validation? 我正在使用这个gem构建一个对象: https : //github.com/schneems/wicked/wiki/Building-Partial-Objects-Step-by-Step validates :name, :presence => true, :if => :active_or_name? validates :details, :presence => true, :if => :active_or_details? validates :image, presence: true, image_size: { width: { min: 400 }, height: { min: 400 } }, :file_size => { :maximum => 5.megabytes.to_i }, if: :active_or_details? function: def active? status == ‘active’ end […]

CarrierWave在文件列保存NULL

我正在使用名为Photo的模型来引用Uploader类.. class Photo < ActiveRecord::Base attr_accessible :title, :album_id belongs_to :album mount_uploader :photo_image, PhotosUploader end class Album :destroy accepts_nested_attributes_for :photos end 但是..当我尝试用图像保存新的相册(或编辑,等等……)时,它不保存文件(collumn photo_image保存为NULL,文件也没有存储。 … views / albums / _form.html.erb 有什么建议吗?

显示Rails Carrierwave URL而不暴露整个路径

我正在制作带有付费下载的网络应用程序,我按照Carrierwave的指南来保护上传 。 一切都在拯救一件事。 这是我目前的设置: 产品文件上传器 … def store_dir “#{Rails.root}/downloads/#{model.product_id}/#{model.id}” end … 路线 get “/downloads/:product_id/:product_file_id/:filename”, :controller => “products”, action: “download”, conditions: {method: :get} 的ProductsController def download product_file = ProductFile.find(params[:product_file_id]) name = File.basename(product_file.file.file.file) send_file “#{Rails.root}/downloads/#{product_file.product.id}/#{product_file.id}/#{name}”, :x_sendfile => true end 问题出在下载路径上。 因为我在File Uploader中指定了#{Rails.root} ,所以该文件保存在名为downloads的公共文件夹外部的文件夹中。 然而,这会产生意想不到的副作用。 当我从模型中检索URL时,我获得了整个绝对路径,而不是相对于Rails Root的路径。 因此,例如, ProductFile.first.file.url返回”/home/doomy/Documents/resamplr/downloads/3/1/aaaa.zip” ,而它应该只返回/downloads/3/1/aaa.zip 。 此行为似乎附加到ProductFileUploader指定的内容。 例如,如果我将store_dir更改为”/downloads/#{model.product_id}/#{model.id}” ,则会在尝试上传到我的PC根目录时出现访问错误。 “downloads/#{model.product_id}/#{model.id}”只是上传到名为downloads的public目录中的新文件夹,这不是我想要做的。 关于如何进行的任何建议? 谢谢。 编辑: […]

validation远程映像实际上是ruby中的映像文件?

我试图找出如何validation我正在为载波提供的内容实际上是一个图像。 我得到我的图片url的来源并没有让我回到所有现场url。 一些图像不再存在。 不幸的是,它并没有真正返回正确的状态代码或任何东西,因为我使用一些代码来检查远程文件是否存在并且是否通过了该检查。 所以现在只是为了安全起见,我想要一种方法来validation我在恢复有效的图像文件之前继续下载它。 这是我用于参考的远程文件检查代码,但我更喜欢能够识别文件是图像的东西。 require ‘open-uri’ require ‘net/http’ def remote_file_exists?(url) url = URI.parse(url) Net::HTTP.start(url.host, url.port) do |http| return http.head(url.request_uri).code == “200” end end

CarrierWave:为多种类型的文件创建1个上传器

我想为多种类型的文件(图像,PDF,video)创建1个上传器 对于每个content_type将执行不同的操作 我如何定义文件的content_type? 例如: if image? version :thumb do process :proper_resize end elsif video? version :thumb do something end end

使用seed.rb文件创建记录时出现CarrierWave :: FormNotMultipart错误

我有一个有image列的模型。 我正在使用CarrierWave上传图片(我正在关注这个rails cast来做这件事。 现在,我想使用seed.rb文件创建一些默认记录,但我未能为图像提供正确的parh / url。 所以,我在List item app/public/images/文件夹中有图像,这是seed.rb文件中的代码: gems = { test1: { name: ‘test1’, description: ‘test1’, image: ‘/public/images/test1.png’, }, test2: { name: ‘test2’, description: ‘test2’, image: ‘/public/images/test2.png’ } gems.each do |user, data| gem = DemoGem.new(data) unless DemoGem.where(name: gem.name).exists? gem.save! end end 当我运行rake db:seed命令时,我收到以下错误: CarrierWave :: FormNotMultipart:您尝试将字符串或路径名分配给上传器,出于安全原因,这是不允许的。 谁能告诉我们如何为图像提供正确的url ?

如何将文件存储在carrierwave的公共文件夹旁边?

Carrierwave默认接受上传者中store_dir生成的url,并store_dir指定rails应用程序的公共文件夹的路径并存储文件。 例如,如果 def store_dir “uploads/#{model.id}” end 然后该文件存储在public/uploads/:attachment_id 如果尝试将存储的文件移出公用文件夹,它仍然保存在公用文件夹中。 有没有人知道如何将文件存储在公共文件夹之外?

使用CarrierWave检索图像高度

我需要能够放置处理过的图像的尺寸。 我有我的ImageUploader类: version :post do process :resize_to_fit => [200, nil] end 有没有办法可以让图像的尺寸与此相似? height = @picture.image_height(:post)

Ruby on Rails send_file,控制器动作中的代码运行两次

我遇到了一个用户可下载文件的奇怪问题,文件正在正常下载,但控制器操作中的其他代码正在执行两次。 我正在使用CarrierWave,它安装在.file上的Document模型中。 我希望用户能够单击此链接下载文件: 这就是我的控制器的样子: def show document = Document.find(params[:id]) # Track this download CourseDownload.create(course: document.course, user: current_user) # Download the file send_file ‘public’ + document.file.url.to_s end 单击该链接时,文件将下载,但会创建2个CourseDownload记录。 在日志中,看起来GET请求发生了两次: Started GET “/documents/1” for 127.0.0.1 at 2014-04-17 18:12:47 -0400 Processing by DocumentsController#show as HTML Parameters: {“id”=>”1”} Document Load (0.2ms) SELECT “documents”.* FROM “documents” WHERE “documents”.”id” = ? […]