Ejemplo n.º 1
0
        public async static Task <ImportServiceResult> ImportFromLocalFileAsync(string pathToFile)
        {
            if (Path.HasExtension(pathToFile))
            {
                using (FileStream fs = System.IO.File.OpenRead(pathToFile))
                {
                    var results = await AnkiTextImportService.ImportFromTextFile(fs);

                    return(results);
                }
            }
            else
            {
                throw new Exception($"Cannot import from: {pathToFile}, file does not exist.");
            }
        }
Ejemplo n.º 2
0
        public async Task <ActionResult <ImportServiceResult> > OnUploadFileAsync(
            IList <IFormFile> files)
        {
            using (var memoryStream = new MemoryStream())
            {
                var firstFile = files[0];
                await firstFile.CopyToAsync(memoryStream);

                if (memoryStream.Length < _settings.MaxUploadBytes)
                {
                    var importDetails = await AnkiTextImportService.ImportFromTextFile(memoryStream);

                    return(importDetails);
                }
                else
                {
                    throw new Exception("File too large.");
                }
            }
        }