Media

Here is a list of methods and examples of working with Media

GetAll()

// returns all media
var media = await client.Media.GetAllAsync();

GetByID

// returns media by ID
var media = await client.Media.GetByIDAsync(123);

Query

Create parametrized request

// returns result of query
var queryBuilder = new MediaQueryBuilder();
queryBuilder.PerPage = 40;
queryBuilder.Page = 2;
queryBuilder.Before = DateTime.Now;
var media = await client.Pages.QueryAsync(queryBuilder);

Create new Media

Create from Stream

// returns created media
// for create media item you must read them to Stream. Media items can be audio, video, image, pdf ot any othe type supported by wordpress
Stream s = File.OpenRead("pathToMedia/media.jpg");
if (await client.IsValidJWTokenAsync())
{
    var createdMedia = await client.Media.CreateAsync(s,"media.jpg");
}

Create from file path

// returns created media
// for create media item you must read them to Stream. Media items can be audio, video, image, pdf ot any othe type supported by wordpress
if (await client.IsValidJWToken())
{
    var createdMedia = await client.Media.CreateAsync(@"C:\pathToFile\media.jpg","media.jpg");
}

Update Media

// returns updated media
var media= client.Media.GetByID(123);
media.Title.Raw = "New Title";

if (await client.IsValidJWTokenAsync())
{
    var updatedMedia = await client.Media.UpdateAsync(media);
}

Delete Media

// returns result of deletion
if (await client.IsValidJWTokenAsync())
{
    var result = await client.Media.DeleteAsync(123);
}