Beispiel #1
0
        public async Task <IActionResult> FileAsync(FullPath path, bool download)
        {
            // Check if path is directory
            if (path.IsDirectory)
            {
                return(new ForbidResult());
            }

            // Check if path exists
            if (!await AzureBlobStorageApi.FileExistsAsync(path.File.FullName))
            {
                return(new NotFoundResult());
            }

            // Check if access is allowed
            if (path.RootVolume.IsShowOnly)
            {
                return(new ForbidResult());
            }

            var contentType = download ? "application/octet-stream" : MimeHelper.GetMimeType(path.File.Extension);

            var stream = new MemoryStream();
            await AzureBlobStorageApi.GetAsync(path.File.FullName, stream);

            stream.Position = 0;

            return(new FileStreamResult(stream, contentType));
        }
Beispiel #2
0
        public async Task <JsonResult> GetAsync(FullPath path)
        {
            var response = new GetResponseModel();

            // Get content
            await using (var stream = new MemoryStream())
            {
                await AzureBlobStorageApi.GetAsync(path.File.FullName, stream);

                stream.Position = 0;

                using (var reader = new StreamReader(stream))
                {
                    response.Content = await reader.ReadToEndAsync();
                }
            }

            return(await Json(response));
        }