3

Image files are meant to be resized as they are uploaded.

The code ' process resize_to_fill: [800, 350]' in the uploader file works in production, but not in my development environment. (I use Vagrant)

My file config/initializers/carrierwave.rb was modified with the following code:

CarrierWave.configure do |config|
  if Rails.env.development?
    config.cache_dir = '/home/vagrant/uploads_tmp/tmp/uploads'
    config.root = '/home/vagrant/uploads_tmp/tmp'
  end
end

Because without this code I get the following error (due to using Windows):

Errno::ETXTBSY in Instructor::CoursesController#create

and can't upload at all in development.

My controller action is as follows:

def create
  @course = current_user.courses.create(course_params)
  if @course.valid?
    redirect_to instructor_course_path(@course)
  else     
    render :new, status: :unprocessable_entity
  end
end

With the error being thrown on the instance variable assignment line.

Since adding the initializer code, some image files get saved in their original size while others get saved as a mostly blank space (with a small stripe from the image showing at the top). I can not seem to identify anything special about the images in either class! Interestingly, this does not appear to happen when the app is deployed to heroku.

Could someone explain:

1) What is causing the original error, and why does the initializer code fix it.

2) What is going wrong with the image uploads?

EDIT

Since posting my question I found that the files do upload without the code fix in the initializer; in that case the issue would be with accessing the file. I omitted the second line of the error message in my original question, which actually must be key to the issue: Text file busy @ unlink_internal - /vagrant/src/flixter/public/uploads/tmp/1499336954-11657-000‌​1-9160/ecriture.jpg Here is the full stack trace (original error without the initializer code fix):

Errno::ETXTBSY (Text file busy @ unlink_internal - /vagrant/src/flixter/public/uploads/tmp/1499420789-13682-000‌​1-6708/ben-white-148‌​430.jpg): app/controllers/instructor/courses_controller.rb:10:in 'create' Rendering /home/vagrant/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems‌​/actionpack-5.0.3/li‌​b/ action_dispatch/middleware/templates/rescues/diagnostics.htm‌​l.erb within rescues/layout Rendering /home/vagrant/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems‌​/actionpack-5.0.3/li‌​b/ action_dispatch/middleware/templates/rescues/_source.html.er‌​b Rendered /home/vagrant/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems‌​/actionpack-5.0.3/li‌​b/action_dispatch/middleware/templates/rescues/_source.html.erb (5.3ms) Rendering /home/vagrant/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems‌​/actionpack-5.0.3/li‌​b/ action_dispatch/middleware/templates/rescues/_trace.html.erb Rendered /home/vagrant/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems‌​/actionpack-5.0.3/li‌​b/a ction_dispatch/middleware/templates/rescues/_trace.html.erb (2.3ms) Rendering /home/vagrant/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems‌​/actionpack-5.0.3/li‌​b/ action_dispatch/middleware/templates/rescues/_request_and_re‌​sponse.html.erb Rendered /home/vagrant/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems‌​/actionpack-5.0.3/li‌​b/a ction_dispatch/middleware/templates/rescues/_request_and_res‌​ponse.html.erb (2.0ms) Rendered /home/vagrant/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems‌​/actionpack-5.0.3/li‌​b/a ction_dispatch/middleware/templates/rescues/diagnostics.html‌​.erb within rescues/layout (26.1ms)

I still don't know why the initializer code partially fixes the bug!

Claire D
  • 31
  • 6
  • I haven't used windows in a long time, and the same for vagrant. It seems though that the original error is specifically related with the filesystem inside vagrant in windows, and probably it tries to write on an open file. Could you try setting config.cache_dir to /blabla/caching - instead of /uploads . If I'm not mistaken carrierwave defaults to /uploads for the final files and that might be an issue? I haven't got the slightest idea if this could be the reason though – m3characters Jul 05 '17 at 20:06
  • Hi Michael, thank you for the help. I had not tried following the home/vagrant/uploads_tmp/tmp/uploads path to the images files, and now I found something else that may lead to some answer (not there yet). In short, the issue seems to be with accessing the uploaded files, not the uploading itself. Will update If I get to an answer! – Claire D Jul 06 '17 at 10:36
  • Can you post your uploader and the stack trace that leads to the error? – m3characters Jul 06 '17 at 11:54
  • https://stackoverflow.com/questions/27359778/errnoetxtbsy-text-file-busy-unlink-internal this might solve your issue? otherwise it's beyond my knowledge – m3characters Jul 07 '17 at 10:47

0 Answers0