Esempio n. 1
0
        private static void WriteFileToDb(ZipInputStream fileFromMemory)
        {
            MemoryStream unzippedFileMemoryStream = new MemoryStream();

            byte[] buffer = new byte[4096];

            using (unzippedFileMemoryStream)
            {
                StreamUtils.Copy(fileFromMemory, unzippedFileMemoryStream, buffer);

                using (var sr = new StreamReader(unzippedFileMemoryStream, System.Text.Encoding.UTF8))
                {
                    unzippedFileMemoryStream.Seek(0, SeekOrigin.Begin);
                    string fileContent = sr.ReadToEnd();
                    using (var context = new FileEntryContext())
                    {
                        context.FileEntries.Add(new FileEntry()
                        {
                            Content = fileContent
                        });
                        context.SaveChanges();
                    }
                }
            }
        }
        public override bool CanPreview(FileEntryContext entry)
        {
            var fn = entry.Name;

            return(fn.EndsWith(".jpg") || fn.EndsWith(".jpeg") || fn.EndsWith(".png") ||
                   fn.EndsWith(".gif"));
        }
Esempio n. 3
0
        public UploadController(ILogger <UploadController> logger, FileEntryContext context)
        {
            _logger  = logger;
            _context = context;

            if (_context.FileEntryItems.Count() == 0)
            {
                _logger.LogWarning("DbSets are empty", "");
            }
        }
Esempio n. 4
0
        public static string Map(FileEntryContext ctx)
        {
            var ext = Path.GetExtension(ctx.Name).ToLowerInvariant().TrimStart('.');

            if (string.IsNullOrWhiteSpace(ext) || !map.ContainsKey(ext))
            {
                return("file-o");
            }

            return(map[ext]);
        }
        private async Task <string> PreviewImageDataForAsync(FileEntryContext context)
        {
            var cacheKey = $"{context.FolderId}-{context.Path}-{context.Name}";

            return(await _cache.GetAsync(cacheKey, async cacheContext =>
            {
                var path =
                    (await _fileFetcher.GetFileToDownloadAsync(context.FolderId,
                                                               Path.Combine(context.Path, context.Name)))
                    .FullName;
                var imageByteData = Resize(path);
                //TODO scale && cache
                var imageBase64Data = Convert.ToBase64String(imageByteData);
                return string.Format("data:image/png;base64,{0}", imageBase64Data);
            }, TimeSpan.FromMinutes(10)));
        }
 public abstract bool CanPreview(FileEntryContext entry);