Rails 上带有 ActiveDirectory 的 Carrierwave 在 store_dir 中添加了 tmp 文件夹
Carrierwave on Rails with ActiveDirectory adds tmp folder in store_dir
我正在尝试使用 carrierwave,它可以很好地上传文件,但我希望我的 mp4 文件位于 public/uploads 目录中。它将它添加到那里,但将其放入 tmp/some-weird-id 文件夹中。我只想要 public/uploads 中的 mp4 文件。这可能吗?如果是这样,如何?我已经尝试编辑 cache_dir,但它仍然添加了那个奇怪的 id 文件夹。
目前的代码如下:
class VideoUploader < CarrierWave::Uploader::Base
# Include RMagick or MiniMagick support:
# include CarrierWave::RMagick
# include CarrierWave::MiniMagick
# Choose what kind of storage to use for this uploader:
storage :file
# storage :fog
def store_dir
"uploads" # This saves to Rails_Root/public/uploads
end
def move_to_cache
true
end
def move_to_store
true
end
这是控制器
def create
@file = params["video"][:file].original_filename
@video = Video.new({ :upload_file_name => @file, :user_id => current_user.id})
@video.file = params["video"][:file]
respond_to do |format|
if @video.save!
format.json { render json: {files: [@video.id]}, status: :created }
end
end
end
您可以指示 Carrierwave 将文件 移动到您的存储目录,而不是通过覆盖上传器中的 move_to_cache
和 move_to_store
方法来复制它.
class MyUploader < CarrierWave::Uploader::Base
def move_to_cache
true
end
def move_to_store
true
end
end
中阅读相关内容
我正在尝试使用 carrierwave,它可以很好地上传文件,但我希望我的 mp4 文件位于 public/uploads 目录中。它将它添加到那里,但将其放入 tmp/some-weird-id 文件夹中。我只想要 public/uploads 中的 mp4 文件。这可能吗?如果是这样,如何?我已经尝试编辑 cache_dir,但它仍然添加了那个奇怪的 id 文件夹。
目前的代码如下:
class VideoUploader < CarrierWave::Uploader::Base
# Include RMagick or MiniMagick support:
# include CarrierWave::RMagick
# include CarrierWave::MiniMagick
# Choose what kind of storage to use for this uploader:
storage :file
# storage :fog
def store_dir
"uploads" # This saves to Rails_Root/public/uploads
end
def move_to_cache
true
end
def move_to_store
true
end
这是控制器
def create
@file = params["video"][:file].original_filename
@video = Video.new({ :upload_file_name => @file, :user_id => current_user.id})
@video.file = params["video"][:file]
respond_to do |format|
if @video.save!
format.json { render json: {files: [@video.id]}, status: :created }
end
end
end
您可以指示 Carrierwave 将文件 移动到您的存储目录,而不是通过覆盖上传器中的 move_to_cache
和 move_to_store
方法来复制它.
class MyUploader < CarrierWave::Uploader::Base
def move_to_cache
true
end
def move_to_store
true
end
end
中阅读相关内容