Esempio n. 1
0
        /// <summary>
        /// Inserts a file
        /// </summary>
        /// <param name="formFile">Form file</param>
        /// <param name="defaultFileName">File name which will be use if IFormFile.OriginalName not present</param>
        /// <param name="virtualPath">Virtual path</param>
        /// <returns>file</returns>
        public virtual File InsertFile(IFormFile formFile, string virtualPath = "")
        {
            var contentType = formFile.ContentType;
            var file        = InsertFile(_downloadService.GetDownloadBits(formFile), contentType, _fileProvider.GetFileNameWithoutExtension(formFile.FileName), _fileProvider.GetFileExtension(formFile.FileName));

            if (string.IsNullOrEmpty(virtualPath))
            {
                return(file);
            }

            file.VirtualPath = _fileProvider.GetVirtualPath(virtualPath);
            UpdateFile(file);

            return(file);
        }
Esempio n. 2
0
        private void UploadFiles(ICollection <IFormFile> httpPostedFile, string newsItemId)
        {
            foreach (var file in httpPostedFile)
            {
                var fileBinary = _downloadService.GetDownloadBits(file);
                var fileName   = file.FileName;
                //remove path (passed in IE)
                fileName = _fileProvider.GetFileNameWithoutExtension(fileName).Replace('.', '_');
                var contentType   = file.ContentType;
                var fileExtension = _fileProvider.GetFileExtension(file.FileName);
                if (!string.IsNullOrEmpty(fileExtension))
                {
                    fileExtension = fileExtension.ToLowerInvariant();
                }

                var download = new File
                {
                    ContentType = contentType,
                    Filename    = _fileProvider.GetFileNameWithoutExtension(fileName),
                    Extension   = fileExtension,
                    NewsItemId  = newsItemId,
                    Name        = file.Name
                };
                if (!StoreInDb) //if file saving into filesystem
                {
                    var pathToFile = _downloadService.SaveFileInFileSystem(fileBinary, fileBinary.GetHashCode().ToString());

                    download.DownloadUrl = _fileProvider.GetFileName(pathToFile);
                }
                else
                {
                    download.DownloadUrl    = string.Empty;
                    download.DownloadBinary = fileBinary;
                }
                _downloadService.InsertDownload(download);
            }
        }
Esempio n. 3
0
        public string GetPathLoadFile(IFormFile load)
        {
            if (load != null)
            {
                _fileProvider.WriteAllBytes(_fileProvider.GetAbsolutePath("files", load.FileName), _downloadService.GetDownloadBits(load));
                //сохраняем файл в папку на сервере
                string xsltPath = Path.Combine(_fileProvider.GetAbsolutePath("files", load.FileName));
                return(xsltPath);
            }

            return(null);
        }