forked from bborn/communityengine
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes attachment_fu uploading problems on windows, see http://epirsch…
- Loading branch information
Showing
1 changed file
with
54 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
require 'tempfile' | ||
class Tempfile | ||
# Returns the size of the temporary file. As a side effect, the IO | ||
# buffer is flushed before determining the size. | ||
def size | ||
if @tmpfile | ||
@tmpfile.fsync | ||
@tmpfile.flush | ||
@tmpfile.stat.size | ||
else | ||
0 | ||
end | ||
end | ||
end | ||
|
||
require 'technoweenie/attachment_fu/backends/s3_backend' | ||
module Technoweenie | ||
module AttachmentFu | ||
module Backends | ||
module S3Backend | ||
protected | ||
def save_to_storage | ||
if save_attachment? | ||
S3Object.store( | ||
full_filename, | ||
(temp_path ? File.open(temp_path, "rb") : temp_data), | ||
bucket_name, | ||
:content_type => content_type, | ||
:access => attachment_options[:s3_access] | ||
) | ||
end | ||
|
||
@old_filename = nil | ||
true | ||
end | ||
end | ||
end | ||
end | ||
end | ||
|
||
module Technoweenie | ||
module AttachmentFu | ||
# Gets the data from the latest temp file. This will read the file into memory. | ||
def temp_data | ||
if save_attachment? | ||
f = File.new( temp_path ) | ||
f.binmode | ||
return f.read | ||
else | ||
return nil | ||
end | ||
end | ||
end | ||
end |