Retrieve the upload progress.

22Aug2011

Allows to retrieve the upload progress of an upload using APC extension.

Request URL

/mediafile/uploadprogress [GET]

Request Authorization

This call needs EGA authentication.

Request Parameters

Parameter (Type)DescriptionRequiredDefault valueMax. length
id (ALPHA_NUM)ID of the upload that has been randomly chosen and provided when the upload was send to the server.Required-
server_id (UINT)The server ID of the upload server. Only required when you have multiple upload servers and with different settings (upload progress).Optional0-

Example Request

mediafile/uploadprogress&id=1442

Example Response

{"status":1,"percentage":-1,"message":"Uploading"}

Comments

Implementation issues

 When implementing this call in SURFmedia, we observed a couple of problems. Maybe these can be of help for others:

1. You need to have APC or uploadprogress extension on the system. Madcap uses APC exclusive. See http://pecl.php.net/package/apc for more information.

2. It is needed that  the 'progress key' in the upload form is before the file input in the form. E.g.:

 

<form action="http://upload.vpcore.snkn.nl/mediafile/upload?upload_ticket=j2MasRdcLMVCjejUdH56CoVT" enctype="multipart/form-data" method="POST">
<input id="progress_key" type="hidden" name="APC_UPLOAD_PROGRESS" value="2685770">
<input class="FlesFileInput" type="file" value="" name="file">
<input type="hidden" value="http://localhost/test.html" name="redirect_uri">
<input type="hidden" value="true" name="create_still">
<input type="submit">
</form>

 

3. In loadbalanced situations using multiple uploadservers, care has to be taken that the status-requests are routed to the correct uploadserver. At least on the VP-Core platform from Kennisnet this is not the case. Statusrequests are distributed between the two uploadservers, and on average 50% of the requests return an  -1 - code, which means 'I don't know this upload'.

If you want to use the

If you want to use the uploadprogress, your system must have apc or uploadprogress extension. We suggest apc.

You can check your system about existence of apc here: http://your-mediamosa/admin/reports/status/php
 
http://pecl.php.net/package/apc
APC (Alternative PHP Cache is a PECL extension of PHP) should be installed on the server where the users upload their files.
 
Your page should contains the following:
/**
  * Determine which upload progress implementation to use, if any available.
  */
function upload_progress_implementation() {
   static $implementation;
   if (!isset($implementation)) {
     if (extension_loaded('apc') && ini_get('apc.rfc1867')) {
       $implementation = 'apc';
     }
     else if (extension_loaded('uploadprogress')) {
       $implementation = 'uploadprogress';
     }
   }
   return $implementation;
}
 
... Your Drupal form should have:
   // Uploadprogress field.
   if ($implementation = upload_progress_implementation()) {
     $upload_progress_key = md5(mt_rand());
      if ($implementation == 'apc') {
       $form['APC_UPLOAD_PROGRESS'] = array('#type' => 'hidden', '#value' => $upload_progress_key);
     }
     else if ($implementation == 'uploadprogress') {
       $form['UPLOAD_IDENTIFIER'] = array('#type' => 'hidden', '#value' => $upload_progress_key);
     }
   }
The id (upload progress key) should be random. Don't use constant.
 
Then you can ask the /mediafile/uploadprogress [GET] REST call with id=$upload_progress_key .
 
If you don't want to use Drupal, this is the pure PHP / HTML version:
<input type="hidden" name="APC_UPLOAD_PROGRESS" id="progress_key" value="<?php echo $upload_progress_key?>" />
 
http://pecl.php.net/bugs/bug.php?id=13583
According to the PECL ticket we should write the progress key before the file input. Eg.
<form action="http://upload.your-mediamosa/mediafile/upload?upload_ticket=xxx" enctype="multipart/form-data" method="POST">
   <input id="progress_key" type="hidden" name="APC_UPLOAD_PROGRESS" value="2685770" />
   <input class="FlesFileInput" type="file" value="" name="file" />
   <input type="hidden" value="http://your-wle/test.html" name="redirect_uri" />
   <input type="hidden" value="true" name="create_still" />
   <input type="submit" />
</form>