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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Image Not Uploading upon upgrade to 2.1.0 #2482

Closed
joshmenden opened this issue May 19, 2020 · 2 comments
Closed

Image Not Uploading upon upgrade to 2.1.0 #2482

joshmenden opened this issue May 19, 2020 · 2 comments

Comments

@joshmenden
Copy link

joshmenden commented May 19, 2020

Hello 馃憢馃徏

I recently upgraded my carrierwave version from 1.2.0 to 2.1.0. I am using fog (AWS) for storage and, after following the instructions in this issue, I set cache_storage =:file.

However, I am still seeing unexpected behavior. The image does save locally to the cache under the expected folder, and when I set the image, and call my_model.uploader.cached? it does return the cache_id. Yet when I call my_model.save!, the image is not saved to the AWS store_dir, neither is the cache image removed.

I attempted to use cache_storage: fog, and have the same issue -- the image saves to an S3 cache bucket, but upon save, does not save to the intended directory.

I've been debugging locally and discovered that, when I call my_model.save! and the following method is called in the gem's lib/carrierwave/uploader/store.rb:

      def store!(new_file=nil)
        cache!(new_file) if new_file && ((@cache_id != parent_cache_id) || @cache_id.nil?)
        if !cache_only && @file && @cache_id
          with_callbacks(:store, new_file) do
            new_file = storage.store!(@file)
            if delete_tmp_file_after_storage
              @file.delete unless move_to_store
              cache_storage.delete_dir!(cache_path(nil))
            end
            @file = new_file
            @cache_id = @identifier = nil
            @staged = false
          end
        end
      end

The @cache_id is nil. I'm assuming that has something to do with the fact that it then does not save the image nor delete the cache.

Please advise on how to proceed. I'd be happy to submit a PR for the issue but I need a little bit of guidance on where in the carrierwave code I should look for the issue.

@DaniG2k
Copy link

DaniG2k commented Aug 3, 2020

Experiencing a similar issue here, after upgrading to Carrierwave from 1.2.0 to 2.1.0

@pomu0325
Copy link

I also had a same issue, but finally found that culprit is in my code.
I was reloading the record within the transaction.

Mounters, which retains uploaded files as a cache, are also reset upon reload:

# Reset cached mounter on record reload
def reload(*)
@_mounters = nil

CarrierWave 2.x now uploads file to the store at after_commit( #2209 ), not at after_save as in 1.x.

So reloading before commit causes files not to be uploaded.

I hope it helps :)

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

4 participants