API Reference

Media.getUploadURL

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 Example

    define('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);
    }


Syntax

int media.getUploadURL ( int vhost, array fileData, int ttl = 300, int v2 = 0, mixed recaptchaToken = false )

Arguments

NameTypeRequiredDefault valueDescription
vhostintRequirednoneThe vhost ID.
fileDataarrayRequirednoneAn array with file information.
ttlintOptional300Time in seconds for URL to be valid
v2intOptional0Use V2 of service
recaptchaTokenmixedOptionalfalse

fileData

fileData is an array that consists of the information that you want to have stored in your media.

NameTypeDescriptionDefaultPossible Values
titleSTRINGThe title associated with the text media item.emptyempty / STRING
messageSTRINGThe media message to be included with the media item.emptySTRING
uidSTRINGThe UID of the user who created the media item.1INT
tagsSTRINGA space separated string containing words to be used as tags for the media item.emptyempty / STRING
filenameSTRINGA string that is going to be assigned as the original name of the file.emptyempty / STRING
extensionSTRING The extension that is going to be set as the original file extension of the text file.empty / STRINGpng,jpeg,mov
channelINTThe channel ID the media item is going to be uploaded into.emptyINT (channel ID)
dateYYYY-MM-DD HH:MM:SSThe date and time the media item started to be uploaded.emptyYYYY-MM-DD HH:MM:SS
urlSTRINGThe url reference.emptyempty
metadataARRAYAn 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' ) )
moderationstatusINTThe initial moderation status of the media item once it is uploaded into MediaFactory.00,1,2,3,4 OR (unmoderated, accepted, denied, deleted, notdenied, moderated, all)
geo_latitudeNUMBERThe 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.empty62.86
geo_longitudeNUMBERThe 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
parentidINT 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.emptyINT
contextSTRINGThe type of media that is being uploaded.'generic''generic', 'all', 'comment', 'note', 'commentnote', 'genericcomment', 'parent','child'
languageSTRINGA 2-letter ISO code associated with the media.n/aSTRING
visibilitySTRINGThe visibility of the media item to the public once uploaded into MediaFactory.'VISIBLE''VISIBLE', 'HIDDEN'
groupidINT or ARRAYThe 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.
empty9499
or
array(9499,9500)

Response

fileData is an array that consists of the information that you want to have stored in your media.

NameTypeDescription
resultINTThe media ID of the newly created media item in MediaFactory.

Sample Response

Code examples

0 comments

Be the first to comment on getUploadURL.

Add a Comment

  • captcha