/// <summary> /// Returns a <see cref="MetaMediaObject"/> given the XElement that contains the data. /// </summary> private MetaMediaObject ParseMetaMediaObject(XElement ele) { var memberList = ele.Element("value").Element("struct").Elements("member"); var name = memberList.SingleOrDefault(m => m.Element("name").Value == "name"); var type = memberList.SingleOrDefault(m => m.Element("name").Value == "type"); var bits = memberList.SingleOrDefault(m => m.Element("name").Value == "bits"); var mediaObj = new MetaMediaObject { Name = name?.Element("value").Value, Type = type?.Element("value").Value, Bits = Convert.FromBase64String(bits == null ? string.Empty : bits.Element("value").Value) }; _logger.LogDebug("ParseMetaMediaObject {@MetaMediaObject}", mediaObj); return(mediaObj); }
public async Task <MetaMediaInfo> NewMediaObjectAsync(string blogId, string userName, string password, MetaMediaObject mediaObject, HttpContext request) { await EnsureValidUserAsync(userName, password); try { var userId = (await _userManager.FindByNameAsync(userName)).Id; var url = await _mediaSvc.UploadMediaAsync(userId, mediaObject.Name, mediaObject.Bits, EAppType.Blog, EUploadedFrom.MetaWeblog); return(new MetaMediaInfo() { Url = url }); } catch (Exception ex) { throw new MetaWeblogException(EMetaWeblogCode.NewMediaObject, ex.Message); } }