This method provides you with a signed URL that you can then use to upload directly to the Filemobile Amazon bucket where original files are stored, once the upload is complete you must use the media.uploadCompleted method to trigger the system to begin conversion of this file.
The fileData array, must contain type, and filename fields, an example of a valid type would be video/mp4, or image/jpg.
Working PHP Exampledefine('APIKEY',''); define('APIENDPOINT','https://api.newspark.ca/services/json'); $sourceFilePath="./test.jpg"; $sourceFileSize=filesize("./test.jpg"); $sourceContentType='image/jpg'; $fileData['title']='This is the title of this Test Image'; $fileData['filename']='test.jpg'; $fileData['message']='This is a description of the test image.'; $fileData['type']=$sourceContentType; $arguments = array( 'APIKEY' => APIKEY, 'method' => 'media.getUploadURL', 'vhost' => '1640', 'v2'=>1, 'fileData' => $fileData, ); $ch = curl_init(); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_URL, APIENDPOINT); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($arguments)); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json')); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $response = curl_exec($ch); curl_close($ch); $data =json_decode($response,true); if($data['status']==1) { $destinationUrl = $data['result']['url']; $mediaID = $data['result']['id']; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $destinationUrl); curl_setopt($ch, CURLOPT_PUT, 1); $fh_res = fopen($sourceFilePath, 'r'); curl_setopt($ch, CURLOPT_INFILE, $fh_res); curl_setopt($ch, CURLOPT_INFILESIZE, filesize($sourceFilePath)); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $response = curl_exec ($ch); fclose($fh_res); curl_close($ch); $arguments = array( 'APIKEY' => APIKEY, 'method' => 'media.uploadCompleted', 'id' => $mediaID ); $ch = curl_init(); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_URL, APIENDPOINT); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($arguments)); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json')); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $response = curl_exec($ch); curl_close($ch); }
int media.getUploadURL ( int vhost, array fileData, int ttl = 300, int v2 = 0 )
Name | Type | Required | Default value | Description |
---|---|---|---|---|
vhost | int | Required | none | The vhost ID. |
fileData | array | Required | none | An array with file information. |
ttl | int | Optional | 300 | Time in seconds for URL to be valid |
v2 | int | Optional | 0 | Use V2 of service |
fileData is an array that consists of the information that you want to have stored in your media.
Name | Type | Description | Default | Possible Values |
---|---|---|---|---|
title | STRING | The title associated with the text media item. | empty | empty / STRING |
message | STRING | The media message to be included with the media item. | empty | STRING |
uid | STRING | The UID of the user who created the media item. | 1 | INT |
tags | STRING | A space separated string containing words to be used as tags for the media item. | empty | empty / STRING |
filename | STRING | A string that is going to be assigned as the original name of the file. | empty | empty / STRING |
extension | STRING | The extension that is going to be set as the original file extension of the text file. | empty / STRING | png,jpeg,mov |
channel | INT | The channel ID the media item is going to be uploaded into. | empty | INT (channel ID) |
date | YYYY-MM-DD HH:MM:SS | The date and time the media item started to be uploaded. | empty | YYYY-MM-DD HH:MM:SS |
url | STRING | The url reference. | empty | empty |
metadata | ARRAY | An ARRAY for any additional information that is to be stored with the media item. It is stored as an associated array in this field. NB 1: You have to set the values of the metadata as an array which itself is a value of the 'users' array. NB 2: When retrieving the information about the media using the API (via function Media.fileGetInfo), you do not specify the 'user' key: the data is returned as: metadata['synopsis'] = 'test1 | empty | array( 'user'=> Array ( 'synopsis' => 'test1', 'pin' => 'test2' ) ) |
moderationstatus | INT | The initial moderation status of the media item once it is uploaded into MediaFactory. | 0 | 0,1,2,3,4 OR (unmoderated, accepted, denied, deleted, notdenied, moderated, all) |
geo_latitude | NUMBER | The latitude of of where the media item was created. This is usually set in conjunction with Google Maps and the user plotting the pin on the map. | empty | 62.86 |
geo_longitude | NUMBER | The latitude of of where the media item was created. This is usually set in conjunction with Google Maps and the user plotting the pin on the map. | empty | -52.44 |
parentid | INT | The media ID that is going to be assigned as the parent to this media item. This would be used in conjunction with context to create text comments. | empty | INT |
context | STRING | The type of media that is being uploaded. | 'generic' | 'generic', 'all', 'comment', 'note', 'commentnote', 'genericcomment', 'parent','child' |
language | STRING | A 2-letter ISO code associated with the media. | n/a | STRING |
visibility | STRING | The visibility of the media item to the public once uploaded into MediaFactory. | 'VISIBLE' | 'VISIBLE', 'HIDDEN' |
groupid | INT or ARRAY | The ID, or array of IDs, of the group that the media item is going to be uploaded into. Note: To specify that the media item should _NOT_ be added to a group, set this value as 0. | empty | 9499 or array(9499,9500) |
fileData is an array that consists of the information that you want to have stored in your media.
Name | Type | Description |
---|---|---|
result | INT | The media ID of the newly created media item in MediaFactory. |