Class ActionController::UploadProgress::Progress
In: lib/action_controller/upload_progress.rb
Parent: Object

THIS IS AN EXPERIMENTAL FEATURE

Which means that it doesn’t yet work on all systems. We‘re still working on full compatibility. It’s thus not advised to use this unless you’ve verified it to work fully on all the systems that is a part of your environment. Consider this an extended preview.

Upload Progress abstracts the progress of an upload. It’s used by the multipart progress IO that keeps track of the upload progress and creating the application depends on. It contians methods to update the progress during an upload and read the statistics such as received_bytes, total_bytes, completed_percent, bitrate, and remaining_seconds

You can get the current Progress object by calling upload_progress instance method in your controller or view.

Methods

Constants

MIN_SAMPLE_TIME = 0.150   Number of seconds between bitrate samples. Updates that occur more frequently than MIN_SAMPLE_TIME will not be queued until this time passes. This behavior gives a good balance of accuracy and load for both fast and slow transfers.
MIN_STALL_TIME = 10.0   Number of seconds between updates before giving up to try and calculate bitrate anymore
MAX_SAMPLES = 20   Number of samples used to calculate bitrate

Attributes

last_update_time  [R]  The last time the upload history was updated
message  [RW]  A message you can set from your controller or view to be rendered in the upload_status_text helper method. If you set a messagein a controller then call session.update to make that message available to your upload_status action.
received_bytes  [R]  Number bytes received from the multipart post
total_bytes  [R]  Total number of bytes expected from the mutlipart post

Public Class methods

Create a new Progress object passing the expected number of bytes to receive

Public Instance methods

Calculates the bitrate in bytes/second. If the transfer is stalled or just started, the bitrate will be 0

Completed percent in integer form from 0..100

Number of seconds elapsed since the start of the upload

Returns true if there are bytes pending otherwise returns false

Number of bytes left for this upload

Calculate the seconds remaining based on the current bitrate. Returns O seconds if stalled or if no bytes have been received

Resets the received_bytes, last_update_time, message and bitrate, but but maintains the total expected bytes

Returns true if there has been a delay in receiving bytes. The delay is set by the constant MIN_STALL_TIME

Returns true if some bytes have been received

[Validate]