Exemplo n.º 1
0
        public async Task <IActionResult> UploadToDatabase(List <IFormFile> files, string description)
        {
            foreach (var file in files)
            {
                var fileName  = Path.GetFileNameWithoutExtension(file.FileName);
                var extension = Path.GetExtension(file.FileName);
                var fileModel = new FileInDb()
                {
                    Created     = DateTime.UtcNow,
                    FileType    = file.ContentType,
                    Extension   = extension,
                    Name        = fileName,
                    Description = description
                };
                using (var dataStream = new MemoryStream())
                {
                    await file.CopyToAsync(dataStream);

                    fileModel.Data = dataStream.ToArray();
                }
                _context.FilesInDb.Add(fileModel);
                _context.SaveChanges();
            }

            TempData["Message"] = "File successfully uploaded to InMemoryDb.";
            return(RedirectToAction("Index"));
        }
Exemplo n.º 2
0
 void CreateDirectoriesAndFiles(DirectoryInfo dirInfo, Folder folder, SessionBase session)
 {
     foreach (DirectoryInfo dir in dirInfo.GetDirectories())
     {
         Folder subFolder = new Folder(dir.Name, folder, session);
         CreateDirectoriesAndFiles(dir, subFolder, session);
     }
     foreach (FileInfo fileInfo in dirInfo.GetFiles())
     {
         FileInDb    file        = new FileInDb(fileInfo.Name, folder);
         byte[]      bytes       = File.ReadAllBytes(fileInfo.FullName);
         FileContent fileContent = new FileContent(bytes);
         session.Persist(fileContent, 10000);
         file.Content = fileContent;
     }
 }
Exemplo n.º 3
0
 //for DB Explorer
 public FileInform(FileInDb fileobj)
 {
     Name = fileobj.Name;
     Path = "DB";
     //Content = fileobj.Content;
     DateOfCreation = fileobj.DateOfCreation;
     Expansion      = fileobj.Expansion;
     Size           = fileobj.Size;
     CategoryId     = fileobj.CategoryId;
     ExpType        = "somefile";
     if (_audioExt.Contains(fileobj.Expansion))
     {
         ExpType = "audio";
     }
     if (_videoExt.Contains(fileobj.Expansion))
     {
         ExpType = "video";
     }
     if (_imgExt.Contains(fileobj.Expansion))
     {
         ExpType = "img";
     }
     FileSourse = fileobj.FileSourse;
 }