shrine: mime_type cannot open: No such file or directory

I’m using determine_mime_type and it works fine most of time but some times, it gives error mime_type cannot open No such file or directory while same file can be uploaded after multiple tries. any idea what is causing this ?

{
  "id": "f972ca5ea746dfc641f390757a3acb7b",
  "storage": "cache",
  "metadata": {
    "filename": "Oman Integrated Residential Project.jpg",
    "size": 111662,
    "mime_type": "cannot open: No such file or directory",
    "cloudinary": {
      "public_id": "cache/c",
      "version": 1540305195,
      "signature": "c",
      "resource_type": "raw",
      "created_at": "2018-10-23T14:33:15Z",
      "tags": [],
      "bytes": 111662,
      "type": "upload",
      "etag": "c",
      "placeholder": false,
      "url": "http://res.cloudinary.com/ccc/raw/upload/v1540305195/cache/c",
      "secure_url": "https://res.cloudinary.com/ccc/raw/upload/v1540305195/cache/c",
      "original_filename": "file"
    }
  }
}

shrine Initializer code for determine_mime_type:

require "cloudinary"
require "shrine/storage/cloudinary"
require "shrine/storage/s3"

Shrine.storages = {
  cache: Shrine::Storage::Cloudinary.new(store_data: true, prefix: "cache", resource_type: :raw), 
  store: Shrine::Storage::Cloudinary.new(store_data: true),
  s3_cache: Shrine::Storage::S3.new(prefix: :cache, access_key_id: aws_settings['k'], region: 'eu-west-1', secret_access_key: aws_settings['k'], bucket: aws_settings['b']),
  s3: Shrine::Storage::S3.new(access_key_id: aws_settings['k'], region: 'eu-west-1', secret_access_key: aws_settings['k'], bucket: aws_settings['b'])
}

Shrine.plugin :activerecord
Shrine.plugin :cached_attachment_data
Shrine.plugin :determine_mime_type

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 18 (12 by maintainers)

Commits related to this issue

Most upvoted comments

Once you switch to the new analyzer, you can fix the files that have an error with a code like this:

Record.find_each do |record|
  if record.attachment.mime_type == "cannot open: No such file or directory"
    attachment = record.attachment
    attachment.open do |io|
      attachment.data["mime_type"] = Shrine.determine_mime_type(io)
    end
    record.update(attachment_data: attachment.to_json) # or `attachment.data` if it's an ActiveRecord JSON column
  end
end

Where you can replace Record with your model, and attachment with your attachment name.