0

Brightscript を使用して AWSaccesskey を使用して期限切れの AWS S3 URL を生成し、XML フィードからビデオ リンクに追加する方法についてのドキュメントを教えてください。

例:http://s3.amazonaws.com/bucket/path?AWSAccessKeyId=44CF9590006BF252F707&Expires=1141889120&Signature=vjbyPxybdZaNmGa%2ByT272YEAiv4%3D

4

1 に答える 1

0

わかりました、答えがないので、brightscript ビットをあきらめました。brightscript で base64_encode 部分を実行する方法がわかりませんでした。

そのため、XML フィードを Linux ホストでホストし、カテゴリ フィードを生成する PHP ページを作成し、Tournas Dimitrios の作業に基づいて、署名済みの AWS S3 期限切れリンクを作成する関数を実行しますhttps://tournasdimitrios1.wordpress.com/2012/ 12/04/how-to-create-expiring-links-for-amazons-s3-with-php/ .

URL の構成を切り替え、XML に & の代わりに & を使用する関数を少し調整するだけです。

結果はうまくいきました.変数に特定の情報とビデオファイルを入力し、カテゴリフィードをphpページに向けるだけです.

カテゴリ1.php

<?php 

// Set header content type for XML for proper browser render
header('Content-Type: text/xml');

// ** EDIT VARIABLE BELOW **

// Set Variables
$genre = "Documentary";
$type = "Video";
$bucketName = "Your S3 Bucket"   ; 
$awsAccessKey = "Your AWS Access Key"  ; 
$awsSecretKey = "Your AWS Secret Key"  ; 

//Build Array of Video Items
$xmlContent = array (
    array ( "title" => "Title 1", 
            "desc" => "Description 1", 
            "sdImg" => "http://Image1.url", 
            "vidFile" => "/path/videofile1.mp4"),
    array ( "title" => "Title 2", 
            "desc" => "Description 2", 
            "sdImg" => "http://Image2.url", 
            "vidFile" => "/path/videofile3.mp4"),
    array ( "title" => "Title 3", 
            "desc" => "Description 3", 
            "sdImg" => "http://Image3.url", 
            "vidFile" => "/path/videofile3.mp4")
    );

// ** FINISHED EDITING VARIABLES**


// Echo initial part or XML document
        echo '<?xml version="1.0" encoding="UTF-8"?>';
        echo '<feed>';

// Loop through the rest of the XML document filling in variables
$count = 1;
foreach ($xmlContent as $video) {

    // Call function to produce expiring signed AWS S3 URL
    $objectPath = $video[vidFile] ; 
    $s3URL =  s3TempLink("$awsAccessKey" , "$awsSecretKey", "$bucketName",  "$objectPath") ; 

        echo ' <item sdImg="'. $video[sdImg] .'" hdImg="'. $video[sdImg] .'">';
        echo '  <title>'. $video[title] .'</title>';
        echo '  <contentType>'. $type .'</contentType>';
        echo '  <contentId>'. $count .'</contentId>';
        echo '  <media>';
        echo '   <streamFormat>mp4</streamFormat>';
        echo '   <streamQuality>SD</streamQuality>';
        echo '   <streamUrl>'. $s3URL .'</streamUrl>';
        echo '  </media>';
        echo '  <media>';
        echo '   <streamFormat>mp4</streamFormat>';
        echo '   <streamQuality>HD</streamQuality>';
        echo '   <streamUrl>'. $s3URL .'</streamUrl>';
        echo '  </media>';
        echo '  <synopsis>'.  $video[desc] .'</synopsis>';
        echo '  <genres>'.  $genre .'</genres>';
        echo ' </item>';
$count++;
}

// Echo last part of XML document
        echo '</feed>';

// Function to create signed expiring AWS S3 link Original by Tournas Dimitrios
    //Reference Link: https://tournasdimitrios1.wordpress.com/2012/12/04/how-to-create-expiring-links-for-amazons-s3-with-php/

function s3TempLink($awsAccessKey, $awsSecretKey, $bucketName , $objectPath , $expires = 5) {
  // Calculating expiry time
  $expires = time() + ($expires * 60) ; 
  $objectPath =  ltrim($objectPath, '/') ;
  $signature = "GET\n\n\n$expires\n".'/'.$bucketName.'/'.$objectPath ; 
  // Calculating  HMAC-sha1
  $hashedSignature = base64_encode(hash_hmac('sha1' ,$signature , $awsSecretKey , true )) ;
  // Constructing the URL
  $url = sprintf('http://s3.amazonaws.com/%s/%s', $bucketName , $objectPath);
  // Constructing the query String
  $queryString = http_build_query( array(
    'AWSAccessKeyId' => $awsAccessKey ,
    'Expires' => $expires ,
    'Signature' => $hashedSignature
            ), '', '&amp;');
    // Apending query string to URL
  return $url.'?'.$queryString ;
}

?>

乾杯!

マーク-

于 2015-03-13T19:49:44.647 に答える