Upload // Download Progress Indicator with Fog

1,782 views
Skip to first unread message

tdewell

unread,
Mar 19, 2012, 7:17:35 PM3/19/12
to ruby-fog
I'm using Fog and CarrierWave in a project to upload and download
video files to Amazon S3.

Is there a way to figure out how much progress (# of bytes uploaded or
downloaded) has been made in uploading the
or downloading the file with Fog?

File uploading or downloading can take a long time and we need to show
the user that progress
is being made somehow, so that they don't think the app has stopped.

geemus (Wesley Beary)

unread,
Mar 21, 2012, 5:17:50 PM3/21/12
to ruby...@googlegroups.com
There isn't currently a way to handle the upload side. Download side
can be done with fog, but it isn't really integrated with Carrierwave.
To use it you can do something like this:

storage = Fog::Storage.new(credentials)
directory = storage.directories.get("bucket")
directory.files.get("object") do |chunk, remaining_bytes, total_bytes|
puts chunk
puts "Remaining: #{remaining_bytes.to_f / total_bytes}%"
end

The block will get called for each chunk (by default each 1MB) and
will include data about the remaining bytes and total_bytes for use
with things like you mentioned. I haven't yet figured out the best
general purpose way to do this on the upload side, but that should at
least help you get part way there on the download side.

Thanks!
wes

Sergio Rubio

unread,
Mar 25, 2012, 11:53:55 AM3/25/12
to ruby...@googlegroups.com
I've got some code to do that with Openstack Swift, could be easily ported to S3 if that interests you:


In particular, the StreamingUploader and/or StreamingUploaderMultipart do all the heavy lifting:


I combine that with progressbar gem to achieve the desired effect. I guess you could hook it up to a rails app.

Hope that helps!

Reply all
Reply to author
Forward
0 new messages