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

mixed media.getUploadURL ( mixed vhost, mixed fileData, mixed ttl = 300, mixed v2 = 0 )

Arguments

NameTypeRequiredDefault valueDescription
vhostmixedRequirednone
fileDatamixedRequirednone
ttlmixedOptional300
v2mixedOptional0

Sample Response

Code examples

0 comments

Be the first to comment on getUploadURL.

Add a Comment

  • captcha