/// <summary> /// metaWeblog.newMediaObject /// </summary> /// <param name="blogID">always 1000 in BlogEngine since it is a singlar blog instance</param> /// <param name="userName">login username</param> /// <param name="password">login password</param> /// <param name="mediaObject">struct with media details</param> /// <param name="request">The HTTP request.</param> /// <returns>struct with url to media</returns> internal MWAMediaInfo NewMediaObject(string blogID, string userName, string password, MWAMediaObject mediaObject, HttpContext request) { ValidateRequest(userName, password); MWAMediaInfo mediaInfo = new MWAMediaInfo(); string newPath = "upfiles/" + DateTime.Now.ToString("yyyyMM") + "/"; string saveFolder = HttpContext.Current.Server.MapPath(ConfigHelper.SitePath + newPath); string fileName = mediaObject.name; // Check/Create Folders & Fix fileName if (mediaObject.name.LastIndexOf('/') > -1) { fileName = mediaObject.name.Substring(mediaObject.name.LastIndexOf('/') + 1); } if (!Directory.Exists(saveFolder)) { Directory.CreateDirectory(saveFolder); } if (File.Exists(saveFolder + fileName)) { // Find unique fileName for (int count = 1; count < 30000; count++) { string tempFileName = fileName.Insert(fileName.LastIndexOf('.'), "_" + count); if (!File.Exists(saveFolder + tempFileName)) { fileName = tempFileName; break; } } } // Save File FileStream fs = new FileStream(saveFolder + fileName, FileMode.Create); BinaryWriter bw = new BinaryWriter(fs); bw.Write(mediaObject.bits); bw.Close(); mediaInfo.url = ConfigHelper.SiteUrl + newPath + fileName; return(mediaInfo); }
/// <summary> /// metaWeblog.newMediaObject method /// </summary> /// <param name="blogId"> /// always 1000 in BlogEngine since it is a singlar blog instance /// </param> /// <param name="userName"> /// login username /// </param> /// <param name="password"> /// login password /// </param> /// <param name="mediaObject"> /// struct with media details /// </param> /// <param name="request"> /// The HTTP request. /// </param> /// <returns> /// struct with url to media /// </returns> internal async Task <MWAMediaInfo> NewMediaObject(string blogId, string userName, string password, MWAMediaObject mediaObject) { var currentUser = await GetVerifyUserAsync(userName, password); //if (!_permissionChecker.IsValid(currentUser, PermissionKeys.PageCreate, PermissionKeys.PostCreate)) //{ // throw new MetaWeblogException("11", "User authentication failed"); //} // var path = _fileManager.Save(mediaObject.name, mediaObject.bits); var mediaInfo = new MWAMediaInfo() { // url = VirtualPathUtility.ToAbsolute(path, Request.ApplicationPath), }; return(mediaInfo); }