public async Task <IHttpActionResult> AddGalleryItem(MediaUploadDetails details) { //validate for XSRF ValidateRequestHeader(Request); if (details == null || String.IsNullOrEmpty(details.GalleryId) || String.IsNullOrEmpty(details.MediaUrl)) { return(BadRequest("Invalid or missing details for media item")); } //store the thumbnail var thumbnailName = MediaUtilities.CreateThumbnailFileName(details.Name); string thumbnailUrl; if (details.MediaContentType.StartsWith("image", StringComparison.InvariantCultureIgnoreCase)) { //for images, we create the thumbnail thumbnailUrl = await _mediaStore.StoreThumbnailAsync(details.Name, thumbnailName, details.MediaContentType, MediaUtilities.CreateThumbnailForImage); } else { //for videos, we copy the static default video thumbnail image instead thumbnailUrl = await _mediaStore.StoreThumbnailAsync( details.Name, thumbnailName, "image/png", (_, thumbnailStream) => { string videoThumbnailPath = System.Web.HttpContext.Current.Server.MapPath(Constants.PATH_STATIC_VIDEO_THUMBNAIL); using (var stm = System.IO.File.OpenRead(videoThumbnailPath)) { stm.CopyTo(thumbnailStream); } }); } var modelItem = _map.Mapper.Map <Models.MediaItemModel>(details); //strip out server details for the image files being stored modelItem.ThumbnailUrl = MakeMediaURLRelative(thumbnailUrl); modelItem.MediaUrl = MakeMediaURLRelative(modelItem.MediaUrl); //update the gallery with the new item await _repo.AddItemToGalleryAsync( details.GalleryId, modelItem); //return JSON content var responseContent = new JObject( new JProperty("thumbnailUrl", thumbnailUrl), new JProperty("newItemId", modelItem.Id)); var response = Request.CreateResponse <JObject>(HttpStatusCode.Created, responseContent); response.Headers.Location = new Uri(details.MediaUrl); return(ResponseMessage(response)); }