Search Results for

    Show / Hide Table of Contents

    Media shares

    By creating a media share you can create a set of media in a custom format for other users to view and download.

    Creating

    To create a share you select/create a format and supply it and a set of media items, collect them in a MediaShare, and pass it to the Store method of the client.

    var client = ClientFactory.GetCurrentUserClient();
    int mediaFormatId = 1; //Set this to the id of the format you want to share
    var ms = new MediaShare
    {
        MediaFormatId = mediaFormatId,
        Name = "My share",
        //The items contains the mediaItems that the share should contain.
        Items = new List<MediaItem> {new MediaItem {Id = 1}, new MediaItem {Id = 2}}
    };
    client.Store(ms);
    //The url to the share is /imagevault/shares/<id of the share> 
    var shareUrl = "http://mySite.com/imagevault/shares/" + ms.Id;
    

    The url to the share contains a key that is the id of the Share.

    Note

    The Store method calls the Save method of the IMediaShareService

    Viewing

    When a user navigates to the share url, thumbnails of the media contained in the share will be displayed. A download link for individual items and for the whole share as a zip file will be present on the share page. Authorization is not needed to view the share page or access the download links.

    Retrieving using the API

    You can also retrieve a MediaShare using the Get method. The query parameter is optional but can contain

    var client = ClientFactory.GetSdkClient();
    
    var mediaShareService = client.CreateChannel<IMediaShareService>();
    
    var id = "sees7yihic";
    var thumbnailFormat = new ThumbnailFormat { Effects = { new ResizeEffect(300, 200, ResizeMode.ScaleToFit) } };
    var query = new MediaItemQuery {
        //specify additional formats to retrieve
        Populate = { MediaFormats = new List<MediaFormatBase> { thumbnailFormat} }
    }; 
    var mediaShare = mediaShareService.Get(id, query);
    Console.WriteLine(@"Retrieved share {0}. Created {1} by {2}", 
        mediaShare.Name, mediaShare.Created.ToShortDateString(), mediaShare.CreatedBy);
    foreach (var mediaItem in mediaShare.Items) {
        //first media is the one specified when creating the share
        var shareMedia = mediaItem.MediaConversions[0];
        //other media is the one supplied in the query
        var thumbnailMedia = mediaItem.MediaConversions[1];
        //all urls for shares are ALWAYS published urls. That means when you request 
        Console.WriteLine("Item "+mediaItem.Name+". Url: "+shareMedia.Url+" Thumb:"+thumbnailMedia.Url);
    }
    

    Listing

    To retrieve all shares that shares a specific media item, use the FindShareByMediaItemId method.

    var client = ClientFactory.GetSdkClient();
    
    var mediaShareService = client.CreateChannel<IMediaShareService>();
    var mediaItemId = 231;
    //gets all mediaShares that contains media item with id 231.
    var mediaShares = mediaShareService.FindShareByMediaItemId(mediaItemId);
    

    Deleting

    To delete a share, call the Delete metod.

    var client = ClientFactory.GetSdkClient();
    
    var mediaShareService = client.CreateChannel<IMediaShareService>();
    var id = "sees7yihic";
    mediaShareService.Delete(id);
    
    In This Article
    Back to top (c) Meriworks 2002-2022