Esempio n. 1
0
        public async Task <IActionResult> DownloadFile(Guid fileID)
        {
            try
            {
                var file = await _messageRepository.GetFileAsync(fileID);

                if (file == null)
                {
                    throw new FileNotFoundException();
                }

                string path = Path.Combine(Environment.CurrentDirectory, file.Path);
                if (!System.IO.File.Exists(path))
                {
                    throw new FileNotFoundException();
                }

                byte[] mas = System.IO.File.ReadAllBytes(path);

                return(File(mas, "application/octet-stream", file.Name));
            }
            catch (FileNotFoundException) { return(NotFound()); }
            catch (Exception) { return(BadRequest()); }
        }