Example #1
0
        public int UploadFileInTempFolder(Stream file, string fileName, string contentType, int contentLenght,string parentFolder = null)
        {
            parentFolder.CannotBeNull("userId");
            fileName.CannotBeNull("filename");
            file.CannotBeNull("file");

             UploadFileInFolder(file, fileName, contentType, contentLenght, true, parentFolder);
            var newId = _fileRepository.InsertTempUpload(parentFolder, fileName,contentType,contentLenght);
            return newId;
        }
Example #2
0
        public void UploadFileInFolder(Stream file, string fileName, string contentType, int contentLenght,bool isTmpFolder = false,string parentFolder =null)
        {
            file.CannotBeNull("file");
            fileName.CannotBeNull("fileName");

            string defaultFolfer = isTmpFolder ? Config.UploadsTempFolder : Config.UploadsFolder;
            var path = Path.IsPathRooted(defaultFolfer)? defaultFolfer: Path.GetFullPath(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, defaultFolfer));

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

            var dir = new DirectoryInfo(path);

            if (!string.IsNullOrEmpty(parentFolder))
            {
                path= dir.CreateSubdirectory(parentFolder).FullName;
            }

            var buffer = new byte[contentLenght];
            file.Read(buffer,0,contentLenght);
            var fileNameFull = Path.Combine(path, fileName);
            using (var fileStream = new FileStream(fileNameFull, FileMode.Create))
            {
                fileStream.Write(buffer,0,contentLenght);
            }

            var versions = Config.UploadThumbSettings;

            if (IsFileImage(fileName))
                FileSystem.ResizeImage(fileNameFull, path, versions);
        }