public async Task <ActionResult <byte[]> > GetCompositeImagePreview(long id, string versionId, int templateCode, int width, int height)
        {
            if (width < 1 || height < 1)
            {
                return(BadRequest("Incorrect width or height"));
            }

            try
            {
                var imageElementValue = await _objectsStorageReader.GetImageElementValue(id, versionId, templateCode);

                if (imageElementValue.TryGetSizeSpecificBitmapImageRawValue(width, height, out var rawValue))
                {
                    return(Redirect(_rawFileStorageInfoProvider.GetRawFileUrl(rawValue)));
                }

                var(imageStream, contentType) = await _imagePreviewService.GetCroppedPreview(imageElementValue, templateCode, width, height);

                return(new FileStreamResult(imageStream, contentType));
            }
            catch (ObjectNotFoundException)
            {
                return(NotFound());
            }
            catch (OperationCanceledException)
            {
                return(TooManyRequests(_retryAfter));
            }
            catch (MemoryLimitedException)
            {
                return(TooManyRequests(_retryAfter));
            }
            catch (ObjectElementInvalidTypeException ex)
            {
                return(BadRequest(ex.Message));
            }
            catch (InvalidBinaryException ex)
            {
                return(Unprocessable(GenerateErrorJsonResult(ex)));
            }
        }
示例#2
0
 public IActionResult RedirectToRaw(Guid sessionId, string fileKey) => Redirect(_rawFileStorageInfoProvider.GetRawFileUrl(sessionId, fileKey));