Listener Settings
Listener Settings
We also provide a web listener for notifications of completed uploads. This is call to a provided URL that contains JSON data containing the uploaded file information.
Listener data:
total_time int |
The number of seconds taken to upload the file. |
url string |
The url to the uploaded file on your Amazon bucket. |
upload_path string |
The final upload path to the uploaded file, including optional prefix. |
upload_id string |
A unique upload identifier for the completed upload. |
original_file_size int |
The file size of the upload in bytes. |
original_filename string |
The original filename of the uploaded file. |
Listener data example:
{
"total_time":3,
"url":"https:\/\/s3.amazonaws.com\/mybucket\/31a17_Example-File.jpg",
"upload_path":"31a17_Example-File.jpg",
"upload_id":"87d892c2bcdb815368fe2058df320e64",
"original_file_size":"7178864",
"original_filename":"Example File.jpg"
}
Receiving listener data
The listener data is sent as JSON in the POST request body. The full event details are included and can be used directly, after parsing the JSON.
Example PHP listener script:
// Retrieve the request's body and parse it as JSON
$input = @file_get_contents("php://input");
$event_json = json_decode($input);
// Do something with $event_json
http_response_code(200); // PHP 5.4 or greater
Responding to the listener
To acknowledge receipt of a listener call, your endpoint should return a 200 HTTP status code. Any other information you return in the request headers or request body will be ignored. Any response code outside the 200 range, including 3xx codes, will indicate to S3Uploader that you did not receive the call. This does mean that a URL redirection or a "Not Modified" response will be treated as a failure.
When a listener call is not successfully received for any reason, S3Uploader will continue trying to send the call every 5 minutes for up to 5 more times.