Skip to content


Subversion checkout URL

You can clone with
Download ZIP


IO_Adapter methods and rewind before saving to S3 #838

wants to merge 2 commits into from

4 participants


I recently updated a project and needed to add missing methods on the new FileAdapter (readbyte, readchar).

Also I was using paperclip-aws and migrated to paperclip that switched to aws-sdk. But having a post_processors that extract informations from attachment make them unreadable on S3 cause of the missing rewind before write to S3 (as paperclip-aws does).


I understand that this is missing. However, do you mind implementing the test for them as well?

Thank you.


sure ;)


May I ask what you need these methods for? I don't really want to proxy a bunch of methods to Tempfile, and if there's a way you can accomplish your task without them, that would be preferred.

@fjg fjg closed this
@fjg fjg reopened this

I am using exifr to extract some data about the picture in post_process and it needs readbyte/readchar.


I was wondering why rewind had been removed for s3 in the latest versions.


@fjg, I assume you have the files locally, or you wouldn't be looking to add these methods to the FileAdapter. Is it possible for you to hand those files to exifr manually, without the Adapter intervening?

The rewind call can be merged in, though I would like to see a test for it that confirms the functionality. @fjg, can you resubmit this pull request preferably with a test, but even if not, can you submit it with just the rewind commit and not the readchar commit? I'll close this one for now.


@jyurek jyurek closed this

@jyurek Actually using the attachment during a post_process is easier through the attachment.queue_for_write[:original] method. The file is already open and readable.
I would not like to open it again and read it through Does it make no sense?

OK for the test and pull-request again

fjg commented

@jyurek @sikachu the rewind was already there. The merge introducing the IO_Adapter removed it (89c8d11). Here is the previous commit with a test that you can merge again: 7cb7384

fjg commented

@jyurek will you add the readchar/readbyte methods? Do you need a dedicated pull-request?

@sikachu sikachu referenced this pull request from a commit
@sikachu sikachu Rewind tempfiles after get saved to storages
Re-fix of #838, #766, #911
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 22, 2012
  1. @fjg
  2. @fjg

    * rewind file before write to S3

    fjg authored
This page is out of date. Refresh to see the latest.
8 lib/paperclip/io_adapters/file_adapter.rb
@@ -39,6 +39,14 @@ def nil?
def read(length = nil, buffer = nil), buffer)
+ def readbyte
+ @tempfile.readbyte
+ end
+ def readchar
+ @tempfile.readchar
+ end
# We don't use this directly, but aws/sdk does.
def rewind
1  lib/paperclip/storage/s3.rb
@@ -283,6 +283,7 @@ def flush_writes #:nodoc:
write_options[:server_side_encryption] = @s3_server_side_encryption
+ file.rewind
s3_object(style).write(file, write_options)
rescue AWS::S3::Errors::NoSuchBucket => e
Something went wrong with that request. Please try again.