jnicklas/carrierwave — Issue #502: Question: CarrierWave and docsplit
Author: shlomizadok
Created: 2011-10-25 09:36:53+00:00
State: open

Hi,
I am trying to do additional processing with docsplit, after uploading a file (a pdf).
I am trying to convert the pdf into images.
My problem is that, the images creation on docsplit does not "respect" the model.id.

Here is my code:

```ruby
class PresentationUploader < CarrierWave::Uploader::Base

include Studyers::Docsplit
# Choose what kind of storage to use for this uploader:
storage :file
#storage :fog

# Override the directory where uploaded files will be stored.
# This is a sensible default for uploaders that are meant to be mounted:
def store_dir
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end

process :process_file
end
```

and I am using a module to do the process:

```ruby

unless defined? Docsplit
begin
require 'docsplit'
rescue LoadError
puts "WARNING: Failed to require docsplit, document processing may fail!"
end
end

module Studyers
module Docsplit
VERSION = 0.1

def pdf?
current_path[-3,3] == 'pdf'
end

def pdf
current_path[0..current_path.rindex('.')] + 'pdf'
end

def length
::Docsplit.extract_length(current_path)
end

def create_pdf
::Docsplit.extract_pdf(current_path, output: output_path) unless pdf?
self
end

def extract_images
::Docsplit.extract_images(self.pdf, :size => %w{1000x}, :format => :png, output: output_path)
self
end

def extract_text
::Docsplit.extract_text(self.pdf, :ocr => true, output: output_path)
self
end

def process_file
self.create_pdf
self.extract_images
end
private

def output_path
"public/#{store_dir}"
end
end
end
```
The problem is: When I create a new resource, it saves the png files under uploads/class_resources/presentation

and not under uploads/class_resources/presentation/ID

When I edit the resource again, the image files are saved in the correct place