Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Cannot view uploaded picture #73

Closed
steverandy opened this Issue · 8 comments

2 participants

@steverandy

I'm using mongoid-3.0. The uploaded picture cannot be viewed. I tried to use Mongoid::GridFS to load the picture with data method. It returns empty string.

@steverandy

From log observation it seems, it performed delete to the chunks after insert to the files.

  MOPED: 127.0.0.1:27017 COMMAND      database=admin command={:ismaster=>1} (0.4761ms)
  MOPED: 127.0.0.1:27017 QUERY        database=linobank_development collection=users selector={"$query"=>{"_id"=>"50a9237a8b6915091b000001"}, "$orderby"=>{:_id=>1}} flags=[] limit=-1 skip=0 fields=nil (0.5140ms)
  MOPED: 127.0.0.1:27017 QUERY        database=linobank_development collection=users selector={"_id"=>"50a9237a8b6915091b000001"} flags=[] limit=0 skip=0 fields=nil (0.7141ms)
  MOPED: 127.0.0.1:27017 QUERY        database=linobank_development collection=users selector={"_id"=>"50a9237a8b6915091b000001"} flags=[] limit=0 skip=0 fields=nil (0.6011ms)
  MOPED: 127.0.0.1:27017 QUERY        database=linobank_development collection=fs.files selector={"$query"=>{"filename"=>"user/picture/50a9237a8b6915091b000001/9e90eee21e7511e2a03a22000a1fbd56_7.jpg"}, "$orderby"=>{:_id=>1}} flags=[] limit=-1 skip=0 fields=nil (0.6919ms)
  MOPED: 127.0.0.1:27017 QUERY        database=linobank_development collection=fs.chunks selector={"$query"=>{"files_id"=>"50b19e548b6915f86e000004"}, "$orderby"=>{"n"=>1}} flags=[] limit=0 skip=0 fields=nil (0.5009ms)
  MOPED: 127.0.0.1:27017 DELETE       database=linobank_development collection=fs.files selector={"_id"=>"50b19e548b6915f86e000004"} flags=[:remove_first] (0.1590ms)
  MOPED: 127.0.0.1:27017 INSERT       database=linobank_development collection=fs.chunks documents=[{"_id"=>"50b19fe68b6915f86e000005", "n"=>0, "files_id"=>"50b19fe68b6915f86e000006", "data"=>#<Moped::BSON::Binary type=:generic length=7616>}] flags=[] (0.1729ms)
  MOPED: 127.0.0.1:27017 QUERY        database=linobank_development collection=fs.files selector={"filename"=>"user/picture/50a9237a8b6915091b000001/9e90eee21e7511e2a03a22000a1fbd56_7.jpg"} flags=[] limit=1 skip=0 fields={:_id=>1} (0.4621ms)
  MOPED: 127.0.0.1:27017 INSERT       database=linobank_development collection=fs.files documents=[{"_id"=>"50b19fe68b6915f86e000006", "contentType"=>"image/jpeg", "length"=>7616, "chunkSize"=>268435456, "uploadDate"=>2012-11-25 00:00:00 UTC, "md5"=>"f4d56a5b2e67cd3288170741b8e3536e", "filename"=>"user/picture/50a9237a8b6915091b000001/9e90eee21e7511e2a03a22000a1fbd56_7.jpg"}] flags=[] (0.1988ms)
  MOPED: 127.0.0.1:27017 DELETE       database=linobank_development collection=fs.chunks selector={"_id"=>"50b19fe68b6915f86e000005"} flags=[:remove_first] (0.1180ms)
@rmm5t
Collaborator

@steverandy Does this problem still exhibit itself with the official carrierwave-mongoid v0.3.0 gem release? The mongoid-3.0 branch relied on a much older version of the mongoid-grid_fs gem.

If it still exhibits itself with v0.3.0, could you please share your configuration in your Carrierwave.configure block, the Uploader that you're using, and the declaration of the uploader in your Mongoid document? Also, is this a fresh install or an upgrade from a previous version of carrierwave-mongoid?

@steverandy

Yes. I have just tried with v0.3.0 earlier today. I did also update mongoid-grid_fs to 1.7.0.
Previously I used 0.3.0 branch.

CarrierWave.configure do |config|
  config.storage = :grid_fs
  config.grid_fs_access_url = "/gridfs"
end
class UserPictureUploader < CarrierWave::Uploader::Base
  include CarrierWave::MiniMagick

  def store_dir
    "#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
  end

  def filename
    return nil unless original_filename.present?
    @memoized_filename ||= "#{Time.now.to_i}.#{file.extension}"
  end

  def extension_white_list
    %w(jpg jpeg gif png)
  end

  process :resize_to_fill => [128, 128]
  process :quality => 80
end
class User
  include Mongoid::Document
  include Mongoid::Timestamps
  include ActiveModel::ForbiddenAttributesProtection

  ...

  mount_uploader :picture, UserPictureUploader

  ...
@steverandy

I made a modification on mongoid-grid_fs. With this commit, I can view the uploaded picture and no chunks was deleted.

steverandy/mongoid-grid_fs@84abe0e

I'm not sure why there is EOFError. I tried unit test on mongoid-grid_fs using file and filename string to GridFS put but none produce EOFError.

@rmm5t
Collaborator

@steverandy I was able to reproduce this problem. Investigating things in more depth now.

@rmm5t
Collaborator

@steverandy, I was only able to reproduce this problem when running Pow. Do you also happen to be running Pow? When I tested the same issue using Webrick, I received no EOFError.

I think this might be related to basecamp/pow#125

I'm running Pow 0.4.0 (which is supposed to remedy the problem), but I'm also running an outdated version of Node.js. Stil digging.

@steverandy

I'm using Pow 0.4.0.

@rmm5t
Collaborator

I've determined this to be an issue with mongoid-grid_fs that exhibits itself anytime something upstream does processing inside a rescue block. In the case of the Pow server, that was the Nack server's main execution block after rescuing from an EOFError.

We just need to get ahoward/mongoid-grid_fs#9 pulled in.

Meanwhile, I'm closing this issue out now that we know the underlying culprit.

@rmm5t rmm5t closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.