Loading...
Area: Episerver Service API
Applies to versions: 1 and higher

Media service

Recommended reading 

The Episerver Service API supports bulk importing of media data such as images, into Episerver. This section describes how to work with bulk operations for media type of data.

Media bulk import methods

In the following we describe the methods to use when importing media files.

Generating the media XML file

For imports using the media service, you can upload an XML file with unc paths or http paths to the media. You also can embed images in a zip file with the media.xml file. See Media service XML for more details.

Bulk import with file

See Media service XML  how to generate the XML needed for the method.

post/episerverapi/commerce/import/assets

C# code sample

using (var client = new HttpClient())
  {
    client.BaseAddress = new Uri("https://mysite.com/");
    client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
    var content = new MultipartFormDataContent();
    var filestream = new FileStream(path, FileMode.Open);
    content.Add(new StreamContent(filestream), "file", "Media.xml");
    var response = client.PostAsync("/episerverapi/commerce/import/assets", content).Result;
    if (response.StatusCode == HttpStatusCode.OK)
      {
        var returnString = response.Content.ReadAsStringAsync().Result;
        returnString = returnString.Replace("\"", "");
        Guid taskId = Guid.Empty;
        Guid.TryParse(returnString, out taskId);
      }
  }

Response

"\"9e4bd26f-b263-488c-a5d3-3e4c9f87ac4f\""

Bulk import with file upload identifier

See Media service XML how to generate the XML needed for the method. For this method to work, you need to a valid upload identifier of a catalog.zip file previously uploaded using the chunked upload methods.

post/episerverapi/commerce/import/assets/{uploadId}

C# code sample

using (var client = new HttpClient())
  {
    client.BaseAddress = new Uri("https://mysite.com/");
    client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
    var response = client.PostAsync(String.Format("episerverapi/commerce/import/assets/{0}", uploadId), new FormUrlEncodedContent(new List<KeyValuePair<String, String>>())).Result;
    if (response.StatusCode == HttpStatusCode.OK)
      {
        var returnString = response.Content.ReadAsStringAsync().Result;
        returnString = returnString.Replace("\"", "");
        Guid taskId = Guid.Empty;
        Guid.TryParse(returnString, out taskId);
      }
  }

Response

"\"9e4bd26f-b263-488c-a5d3-3e4c9f87ac4f\""

Related topics

Do you find this information helpful? Please log in to provide feedback.

Last updated: Oct 20, 2016

Recommended reading