1
votes

I need to upload files from local system to azure media services. I have uploaded the content from client machine to AMS using HTML5 uploader(browser chunk upload). reference from, http://gauravmantri.com/2013/02/16/uploading-large-files-in-windows-azure-blob- storage-using-shared-access-signature-html-and-javascript.

Now I need to move the uploaded file from blob storage to Azure Media Services as asset and publish. How to achieve this. can anyone provide example for this process.

1

1 Answers

1
votes

From this link: Copying an Existing Blob into a Media Services Asset

/// <summary>
    /// Creates a new asset and copies blobs from the specifed storage account.
    /// </summary>
    /// <param name="mediaBlobContainer">The specified blob container.</param>
    /// <returns>The new asset.</returns>
    static public IAsset CreateAssetFromExistingBlobs(CloudBlobContainer mediaBlobContainer)
    {
        // Create a new asset. 
        IAsset asset = _context.Assets.Create("CopyBlob_" + Guid.NewGuid(), AssetCreationOptions.None);

        IAccessPolicy writePolicy = _context.AccessPolicies.Create("writePolicy", TimeSpan.FromHours(24), AccessPermissions.Write);
        ILocator destinationLocator = _context.Locators.CreateLocator(LocatorType.Sas, asset, writePolicy);

        CloudBlobClient destBlobStorage = _destinationStorageAccount.CreateCloudBlobClient();

        // Get the asset container URI and Blob copy from mediaContainer to assetContainer. 
        string destinationContainerName = (new Uri(destinationLocator.Path)).Segments[1];

        CloudBlobContainer assetContainer = destBlobStorage.GetContainerReference(destinationContainerName);

        if (assetContainer.CreateIfNotExists())
        {
            assetContainer.SetPermissions(new BlobContainerPermissions
            {
                PublicAccess = BlobContainerPublicAccessType.Blob
            });
        }

        var blobList = mediaBlobContainer.ListBlobs();
        foreach (var sourceBlob in blobList)
        {
            var assetFile = asset.AssetFiles.Create((sourceBlob as ICloudBlob).Name);
            CopyBlob(sourceBlob as ICloudBlob, assetContainer);
            assetFile.ContentFileSize = (sourceBlob as ICloudBlob).Properties.Length;
            assetFile.Update();
        }

        destinationLocator.Delete();
        writePolicy.Delete();

        // Since we copied a set of Smooth Streaming files, 
        // set the .ism file to be the primary file. 
        SetISMFileAsPrimary(asset);

        return asset;
    }