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

in Windows, uploading to Amazon S3 and Rackspace Cloud Files fails #14

Open
diegolopez opened this issue Apr 30, 2010 · 9 comments
Open

Comments

@diegolopez
Copy link

You have to change the save_to_storage from s3 and rackspace backends so instead of:
(temp_path ? File.open(temp_path) : temp_data)
you do:
(temp_path ? File.open(temp_path, "rb") : temp_data)

Example for rackspace:

      def save_to_storage
        if save_attachment?
          @object = @@container.create_object(full_filename)
          @object.write((temp_path ? File.open(temp_path, "rb") : temp_data))
        end

        @old_filename = nil
        true
      end
@technoweenie
Copy link
Owner

Does it work with just File.open(temp_path, "rb")? #read will read it all into memory, which you do not want for large files. The S3Object#write method is designed to stream IO objects.

@diegolopez
Copy link
Author

Yes!

So the example is:
def save_to_storage
if save_attachment?
@object = @@container.create_object(full_filename)
#FIXME: ugly hack to get it running on windows
#somehow when You give file handle it won't read it
if RUBY_PLATFORM =~ /(:?mswin|mingw)/
@object.write((temp_path ? File.open(temp_path, "rb") : temp_data))
else
@object.write((temp_path ? File.open(temp_path) : temp_data))
end
end

    @old_filename = nil
    true
  end

Thanks!!
I will edit the previous post.

@technoweenie
Copy link
Owner

Is this from the master branch? I haven't used this plugin in years. Also, you don't need the RUBY_PLATFORM check. You can pass 'rb' to it on unix systems. Other non-windows systems happily ignore the 'b'.

@diegolopez
Copy link
Author

Does linux works ok with File.open(temp_path, "rb") ?
So we don't need to do that ugly condition!

@technoweenie
Copy link
Owner

Correct.

@diegolopez
Copy link
Author

I haven't commited my code...

@technoweenie
Copy link
Owner

You should do that...?

@diegolopez
Copy link
Author

ok. thanks. I'll do it.

@technoweenie
Copy link
Owner

Ah yes, a pull request would be great if you want credit :)

j1wilmot pushed a commit to Punchbowl/attachment_fu that referenced this issue Jul 11, 2017
Fix crash with protected_attributes and rails 4.2
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

2 participants