Ejemplo n.º 1
0
        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)));
            }
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> RedirectToRaw(long id, string versionId, int templateCode)
        {
            try
            {
                var imageElementValue = await _objectsStorageReader.GetImageElementValue(id, versionId, templateCode);

                return(Redirect(_rawFileStorageInfoProvider.GetRawFileUrl(imageElementValue.Raw)));
            }
            catch (ObjectNotFoundException)
            {
                return(NotFound());
            }
            catch (ObjectElementInvalidTypeException ex)
            {
                return(BadRequest(ex.Message));
            }
        }