Example #1
0
        private async Task <IActionResult> InternalDownload(string orgSlug, string dsSlug, string[] paths, bool isInline)
        {
            try
            {
                // If only one file is requested, we can leverage the local file system
                if (paths?.Length == 1 &&
                    await _objectsManager.GetEntryType(orgSlug, dsSlug, paths[0]) != EntryType.Directory)
                {
                    var r = await _objectsManager.Get(orgSlug, dsSlug, paths[0]);

                    return(PhysicalFile(r.PhysicalPath, r.ContentType, isInline ? null : r.Name, true));
                }

                var res = await _objectsManager.DownloadStream(orgSlug, dsSlug, paths);

                Response.StatusCode  = 200;
                Response.ContentType = res.ContentType;

                Response.Headers.Add("Content-Disposition",
                                     isInline ? "inline" : $"attachment; filename=\"{res.Name}\"");

                await res.CopyToAsync(Response.Body);

                return(new EmptyResult());
            }
            catch (Exception ex)
            {
                _logger.LogError(ex,
                                 "Exception in Objects controller Download('{OrgSlug}', '{DsSlug}', '{Paths}', '{IsInline}')",
                                 orgSlug, dsSlug, paths != null ? string.Join("; ", paths) : string.Empty, isInline);

                return(ExceptionResult(ex));
            }
        }
Example #2
0
        public async Task <IActionResult> Download([FromRoute] string orgSlug, [FromRoute] string dsSlug,
                                                   [FromQuery(Name = "path")] string pathsRaw, [FromQuery(Name = "inline")] int?isInlineRaw)
        {
            try
            {
                var paths    = pathsRaw?.Split(",", StringSplitOptions.RemoveEmptyEntries);
                var isInline = isInlineRaw == 1;

                _logger.LogDebug("Objects controller Download('{OrgSlug}', '{DsSlug}', '{PathsRaw}', '{IsInlineRaw}')", orgSlug, dsSlug, pathsRaw, isInlineRaw);

                // If only one file is requested, we can leverage the local file system
                if (paths?.Length == 1)
                {
                    var r = await _objectsManager.Get(orgSlug, dsSlug, paths[0]);

                    return(PhysicalFile(r.PhysicalPath, r.ContentType, isInline ? null : r.Name, true));
                }

                var res = await _objectsManager.DownloadStream(orgSlug, dsSlug, paths);

                Response.StatusCode  = 200;
                Response.ContentType = res.ContentType;

                Response.Headers.Add("Content-Disposition",
                                     isInline ? "inline" : $"attachment; filename=\"{res.Name}\"");

                await res.CopyToAsync(Response.Body);

                return(new EmptyResult());
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "Exception in Objects controller Download('{OrgSlug}', '{DsSlug}', '{PathsRaw}')", orgSlug, dsSlug, pathsRaw);

                return(ExceptionResult(ex));
            }
        }