Skip to content
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

Question: CarrierWave and docsplit #502

Closed
shlomizadok opened this issue Oct 25, 2011 · 5 comments
Closed

Question: CarrierWave and docsplit #502

shlomizadok opened this issue Oct 25, 2011 · 5 comments

Comments

@shlomizadok
Copy link

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:

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 :extract_images
end

and I am using a module to do the process:

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

      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

@trevorturk
Copy link
Contributor

Perhaps you could provide a simple sample application that reproduces this problem? It seems like the ID isn't set at the time you're doing this processing, but I'm not sure what to suggest that would help.

@shlomizadok
Copy link
Author

Hey,
Thank you so much for helping.
It does seem that the ID isn't set on the time of processing - don't know how to make the processing after ID is set :(
This is part of a startup I am doing, so this is a work in progress.
I have opened for you the option to look at a live sample.
The code behind it is the one on the issue.
http://studyers.com/class_resources

I'll leave it for a while before closing it back (so people won't upload all their crap :)

Thanks for helping me.

PS,
It will be an open source project at the end

@trevorturk
Copy link
Contributor

Sorry, I meant for you to create a sample application to isolate the problem like this:

https://github.com/trevorturk/carrierwave-issue-381

@shlomizadok
Copy link
Author

Sorry it took me so long (way too busy these days)
https://github.com/shlomizadok/carrierwave-issue-502

This is part of an open source project, so any help would be much appreciated.

@bensie
Copy link
Member

bensie commented Dec 19, 2011

If you can come up with a reproducible bug, please post it here -- otherwise post this question on the google group or on stack overflow so you can get help from others.

@bensie bensie closed this as completed Dec 19, 2011
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants