示例#1
0
        public IActionResult NewMediaObject(string blogid, string username, string password, MediaObject media)
        {
            string relative = BlogRepository.SaveMedia(blogid, media);

            return new XmlRpcResult(new { url = $"{Request.Scheme}://{Request.Host}{relative}" });
        }
示例#2
0
        public string SaveMedia(string blogid, MediaObject media)
        {
            var filesFolder = String.Format(_filesFolder, blogid);

            if (!Directory.Exists(filesFolder))
            {
                Directory.CreateDirectory(filesFolder);
            }

            string extension = Path.GetExtension(media.Name);

            string relative = filesFolder + Guid.NewGuid();

            if (string.IsNullOrWhiteSpace(extension))
            {
                extension = ".bin";
            }
            else
            {
                extension = "." + extension.Trim('.');
            }

            relative += extension;

            string file = RootFolder + relative.Replace("/", "\\");

            File.WriteAllBytes(file, media.Bits);

            return relative;
        }