-
Notifications
You must be signed in to change notification settings - Fork 165
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Carrierwave not uploading the file. #154
Comments
we are facing same issue.Please,let us know if anyone has found solution for this. |
For any other poor fool who comes across this at a later date, here you are: use |
@nsantiago2719 @Divya-Pandit @streetlogics I tried to tackle this issue but was not able to reproduce it. What am I missing? Here is what I tried: describe 'Issue 158' do
let(:model_class) { reset_mongo_class }
before do
model_class.create!
end
shared_examples 'persist avatar' do
if Gem::Version.new(Mongoid::VERSION) >= Gem::Version.new(4)
it 'save', aggregate_failures: true do
record = model_class.first
expect(record.image).to be_blank
record.image = file
record.save!
expect(record.image.path).to eq(public_path('uploads/test.jpeg'))
expect(model_class.first.image.path).to eq(public_path('uploads/test.jpeg'))
end
it 'update', aggregate_failures: true do
record = model_class.first
expect(record.image).to be_blank
expect(record.update(image: file)).to be_truthy
expect(record.image.path).to eq(public_path('uploads/test.jpeg'))
expect(model_class.first.image.path).to eq(public_path('uploads/test.jpeg'))
end
end
end
context 'with stub_file' do
let(:file) { stub_file('test.jpeg') }
include_examples 'persist avatar'
end
context 'with file upload' do
let(:file) do
{
"filename" => "test.jpeg",
"type" => "image/jpeg",
"name" => "avatar",
"tempfile" => stub_tempfile('test.jpeg'),
"head" => "Content-Disposition: form-data; name=\"avatar\"; filename=\"test.jpeg\"\r\nContent-Type: image/jpeg\r\n"
}.with_indifferent_access
end
include_examples 'persist avatar'
end
end |
@leoarnold , I'm not sure because this was a project of mine 4 years ago and as far as I remember I didn't proceed to use this since I wasn't able to fix that problem in time. |
In my code, I was calling |
@streetlogics The way you describe works. That's what I use day to day with no observable problem (at least in our setup). Should anyone experience the same issue: Please be specific in what kind of object you are actually assigning. My hunch is that - in the initial example - |
I can assure you it didn't work in my case where I was using |
Also - what does your uploader look like? |
This was what I was using:
|
Wondering if maybe it could be something to do with the extra step of uploading to s3 via fog? |
@streetlogics Our uploader looks quite the same. Also uses S3. Maybe your access to S3 lacks certain permissions, leading to a silent fail. I gave mine full permissions on its S3 bucket. |
Yah my s3 credentials are setup and working fine. I'm not having the issue anymore as I've implemented my "workaround" using For reference, here's all the mongo related gems I'm using in case one of them is potentially interacting weirdly:
|
Here's my config/initializers/carrierwave.rb in case it helps too, maybe it's something with using
|
@streetlogics When you write Can you please paste a sample of puts params[:user][:avatar].inspect |
I have been using carrierwave-mongoid for my projects. But this is the first time that I encounter this problem. I'm trying to upload a Avatar for the user. I have mounted the uploader, configure the options, and followed the steps every time I use carrierwave. But after uploading the avatar field turns out to old every image upload. Here's a code in my controller
I checked the value of
params[:user][:avatar]
and it returns me the file. But when I checked@user.avatar
's value it returns me this path/uploads/user/avatar/56d00fddc001ff0bd5616990/_old_
. Oh and by the way I checked the path but there is nothing.The text was updated successfully, but these errors were encountered: