예제 #1
0
 protected Base(OAuthToken oauthToken, string strAccountID, string strPolicyKey)
 {
     AccountID = strAccountID;
     PolicyKey = strPolicyKey;
     Token     = oauthToken;
 }
예제 #2
0
 protected Base(OAuthToken oauthToken)
 {
     Token = oauthToken;
 }
예제 #3
0
 protected Base(OAuthToken oauthToken, string strAccountID)
 {
     AccountID = strAccountID;
     Token     = oauthToken;
 }
예제 #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="T:BrightcoveAPI.CMS"/> class.
 /// </summary>
 /// <param name="theToken">The token.</param>
 /// <param name="strAccountID">String account identifier.</param>
 public CMS(OAuthToken theToken, string strAccountID) : base(theToken, strAccountID)
 {
 }
        /// <summary>
        /// Uploads the file.
        /// </summary>
        /// <returns>The file.</returns>
        /// <param name="oauthToken">Oauth token.</param>
        /// <param name="strAccountID">String account identifier.</param>
        /// <param name="strVideoID">String video identifier.</param>
        /// <param name="strFullPath">String full path.</param>
        public string UploadFile(OAuthToken oauthToken, string strAccountID, string strVideoID, string strFullPath)
        {
            if (!Helper.IsDigitsOnly(strVideoID))
            {
                throw new BrightcoveAPIException("Video ID is not valid.");
            }

            if (!Helper.IsDigitsOnly(strAccountID))
            {
                throw new BrightcoveAPIException("Account ID is not valid.");
            }

            string strFilename    = Path.GetFileName(strFullPath);
            string strFilenameURI = Uri.EscapeDataString(strFilename);

            ///////////////////////////////////////////////////////////////////////////
            /// Use Source File Upload API to create a S3 upload URL for the video
            ///////////////////////////////////////////////////////////////////////////
            //Console.Write("Creating S3 URL for '{0}': ", strFilename);

            string strApiResponse = GetS3URL(strVideoID, strFilenameURI);

            dynamic createAssetResponse = SimpleJson.DeserializeObject(strApiResponse);

            //var createAssetResponse = JsonValue.Parse(strApiResponse);

            if (strApiResponse.Contains("error_code"))
            {
                throw new BrightcoveAPIException(createAssetResponse[0]["error_code"]);
                //Console.WriteLine("Failed ({0}).", createAssetResponse[0]["error_code"]);
                //return(string.Empty);
            }

            //Console.WriteLine("Done.");

            //Console.WriteLine("API URL used: {0}", strClientURL);
            //Console.WriteLine("Response: {0}", createAssetResponse);

            ///////////////////////////////////////////////////////////////////////////
            /// Copy needed data from the API response for ease of use
            ///////////////////////////////////////////////////////////////////////////
            string strBucketName      = createAssetResponse["bucket"];
            string strKeyName         = createAssetResponse["object_key"];
            string strAccessKey       = createAssetResponse["access_key_id"];
            string strSecretAccessKey = createAssetResponse["secret_access_key"];
            string strToken           = createAssetResponse["session_token"];
            string strAPIRequestURL   = createAssetResponse["api_request_url"];

            ///////////////////////////////////////////////////////////////////////////
            /// Use Amazon S3 API to upload local file to the generated S3 URL
            ///////////////////////////////////////////////////////////////////////////
            //Console.Write("Uploading to S3: 0/0");
            //Console.SetCursorPosition(0, Console.CursorTop);

            try
            {
                var s3Client            = new AmazonS3Client(strAccessKey, strSecretAccessKey, strToken, Amazon.RegionEndpoint.USEast1);
                var fileTransferUtility = new TransferUtility(s3Client);

                // Use TransferUtilityUploadRequest to configure options.
                // In this example we subscribe to an event.
                var uploadRequest = new TransferUtilityUploadRequest
                {
                    BucketName = strBucketName,
                    FilePath   = strFullPath,
                    Key        = strKeyName
                };

                //Console.WriteLine("BucketName: {0}", strBucketName);
                //Console.WriteLine("FilePath: {0}", strFullPath);
                //Console.WriteLine("Key: {0}", strKeyName);

                uploadRequest.UploadProgressEvent +=
                    new EventHandler <UploadProgressArgs>
                        (uploadRequest_UploadPartProgressEvent);

                fileTransferUtility.Upload(uploadRequest);
                //Console.WriteLine("Upload completed: {0}", strAPIRequestURL);
            }
            catch (AmazonS3Exception e)
            {
                throw e;
                //Console.WriteLine(e.Message, e.InnerException);
                //return(string.Empty);
            }

            return(strAPIRequestURL);
        }
 public SourceFileUpload(OAuthToken oauthToken, string strAccountID, string strVideoID) : base(oauthToken, strAccountID)
 {
     myStrVideoID = strVideoID;
 }