我想通过Shrine上载器gem上载一个xls文件(Libreoffice),但是我得到了一个回滚错误,比如文件类型必须是一个..(在我的initializers/Shrine.rb中有mime类型)。这是我的神殿
require "shrine"
require "shrine/storage/s3"
s3_options = {
bucket: "#{Rails.application.secrets[:aws_bucket_name]}",
access_key_id: "#{Rails.application.secrets[:aws_access_key_id]}",
secret_access_key: "#{Rails.application.secrets[:aws_secret_access_key]}",
region: "#{Rails.application.secrets[:aws_region_name]}"
}
Shrine.storages = {
cache: Shrine::Storage::S3.new(prefix: "cache", **s3_options),
store: Shrine::Storage::S3.new(prefix: "store", **s3_options),
#public_store: Shrine::Storage::S3.new(public: true, upload_options: { cache_control: "max-age=15552000" }, **s3_options)
}
Shrine.plugin :activerecord
Shrine.plugin :instrumentation
Shrine.plugin :determine_mime_type, analyzer: :marcel
Shrine.plugin :cached_attachment_data
Shrine.plugin :restore_cached_data
Shrine.plugin :presign_endpoint, presign_options: -> (request) {
# Uppy will send the "filename" and "type" query parameters
filename = request.params["filename"]
type = request.params["type"]
{
content_disposition: ContentDisposition.inline(filename), # set download filename
content_type: type, # set content type (required if using DigitalOcean Spaces)
content_length_range: 0..(10*1024*1024), # limit upload size to 10 MB
}
}
Shrine.plugin :derivation_endpoint,
secret_key: "secret",
download_errors: [defined?(Shrine::Storage::S3) ? Aws::S3::Errors::NotFound : Errno::ENOENT]
这是我的shrine_uploader.rb
class ShrineUploader < Shrine
plugin :processing
plugin :validation_helpers # to validate image data
plugin :versions
plugin :add_metadata
plugin :delete_raw
plugin :recache
plugin :default_storage, cache: :cache, store: :store
Attacher.validate do
validate_max_size 10.megabyte
validate_mime_type_inclusion ['image/jpg', 'image/jpeg', 'image/png', 'image/gif','image/tiff', 'application/pdf', 'application/msword', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', 'application/vnd.ms-excel', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'application/vnd.ms-powerpoint', 'application/vnd.openxmlformats-officedocument.presentationml.presentation', 'application/vnd-xls']
end
def generate_location(io, context)
#type = context[:record].class.name.downcase if context[:record]
type = context[:record].patron_id if context[:record]
style = context[:version] if context[:version]
name = super # the default unique identifier[type, style, name].compact.join("/")
end
end
我可以上传xlsx文件,但是我不明白为什么我不能上传xls文件,即使mime类型是application/vnd.ms-excel。
谢谢你的帮助。
class FileUploader < Shrine
plugin :validation_helpers
plugin :pretty_location
plugin :determine_mime_type
Attacher.validate do
validate_max_size 150.megabytes, message: "Large file sorry"
#validate_mime_type %w[image/jpeg image/png image/jpg]
validate_extension_inclusion %w[jpg jpeg png pdf xlsx]
end
end
validate_extension_inclusive%w[jpg jpeg png pdf xlsx]帮助我<3
在CKAN 2.4.1中,install datapusher和.csv文件上传到datastore是正确的,但是当test.xls或.xlsx文件上传到datastore失败时,datapusher搜索文件字段头时,在datapusher.error.log中: 配置文件中:ckan.datapusher.formats=csv xls xlsx tsv application/csv appl
我正在尝试上载文件,但无法工作: 有用信息:运行IIS Express(使用PHP5.3)-Windows 7 Professional 32位 代码: move_uploaded_file($_FILES[图像][名称],/图像/。$_FILES["Imagem"]["name"])或die("Error:".print_r($_FILES)); 它打印:数组([imagem]= 我确信路径是正
我有一个表单,其中一个信息,用户将上传一个图像。我想将图像的路径存储在数据库中,并将图像保存到服务器上的文件夹中。 使用以下方法打开表单:
我正在尝试用Java以块形式上载文件。 我的块上载功能: 这就是文件服务API的外观:
嗨,我正在尝试使用多部分表单上传多个文件 我使用这个,但我得到了错误的请求状态,我如何上传多个文件?
如果我尝试上载文档文件,则会出现以下错误“上载路径似乎无效”。我将路径替换为绝对路径,然后我也得到了这个错误。请告诉我如何解决这个问题`