Skip to content

Commit 7d03563

Browse files
committed
Merge branch 'fix/png-jpg-view-source-document' into 'develop'
Fix/png jpg view source document See merge request genaiic-reusable-assets/engagement-artifacts/genaiic-idp-accelerator!225
2 parents 0877b5f + 7a51e42 commit 7d03563

File tree

4 files changed

+61
-9
lines changed

4 files changed

+61
-9
lines changed

CHANGELOG.md

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,11 @@ SPDX-License-Identifier: MIT-0
2323
- Markdown table headers now explicitly left-aligned using `|:-----|:-----------|` format for consistent appearance
2424

2525

26-
2726
### Fixed
28-
- **OCR Service Image Processing for PNG/JPG Files**
29-
- Fixed issue where PNG files were being unnecessarily converted to JPEG format and resized
30-
- PNG and JPG files now preserve their original format when stored in S3
31-
- Image resolution is preserved by default unless explicitly configured via `resize_config`
32-
- DPI settings now only apply to PDF files, not to image files
33-
- Resolves issue where PNG files were being converted to lower resolution JPG files
27+
- Fixed issue where PNG files were being unnecessarily converted to JPEG format and resized to lower resolution with lost quality
28+
- Fixed issue where PNG and JPG image files were not rendering inline in the Document Details page
29+
- Fixed issue where PDF files were being downloaded instead of displayed inline
30+
3431

3532

3633
## [0.3.7]

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.3.8-wip3
1+
0.3.8-wip4

src/ui/src/components/common/generate-s3-presigned-url.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ const parseS3Url = (s3Url) => {
3434
return { bucket, key };
3535
};
3636

37-
const generateS3PresignedUrl = async (url, credentials) => {
37+
const generateS3PresignedUrl = async (url, credentials, options = {}) => {
3838
// If it's already a special URL (like detailType), return as is
3939
if (url.includes('detailType')) {
4040
return url;
@@ -72,7 +72,24 @@ const generateS3PresignedUrl = async (url, credentials) => {
7272

7373
// Parse the URL for the presigner
7474
const s3ObjectUrl = parseUrl(newUrl);
75+
76+
// Determine file type from key to set appropriate content disposition
77+
const fileExtension = key.split('.').pop().toLowerCase();
78+
const isDisplayableFile = ['pdf', 'jpg', 'jpeg', 'png', 'gif', 'svg', 'webp'].includes(fileExtension);
79+
80+
// Add query parameters for inline display if it's a displayable file type
81+
if (isDisplayableFile && options.forceInline !== false) {
82+
s3ObjectUrl.query = s3ObjectUrl.query || {};
83+
s3ObjectUrl.query['response-content-disposition'] = 'inline';
84+
85+
// Set appropriate content type for PDFs to ensure proper display
86+
if (fileExtension === 'pdf') {
87+
s3ObjectUrl.query['response-content-type'] = 'application/pdf';
88+
}
89+
}
90+
7591
logger.debug('Canonical URL:', newUrl);
92+
logger.debug('Query parameters:', s3ObjectUrl.query);
7693

7794
// Create presigner instance
7895
const presigner = new S3RequestPresigner({

src/ui/src/components/document-viewer/FileViewer.jsx

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,44 @@ const FileViewer = ({ objectKey }) => {
239239
</Box>
240240
);
241241
}
242+
// For image files, display them inline using img tag
243+
if (fileType === 'image') {
244+
return (
245+
<Box className="document-container" padding={{ top: 's' }}>
246+
<Box textAlign="center">
247+
<img
248+
src={presignedUrl}
249+
alt="Document preview"
250+
style={{
251+
maxWidth: '100%',
252+
maxHeight: '800px',
253+
height: 'auto',
254+
objectFit: 'contain',
255+
}}
256+
onError={(e) => {
257+
// On error, replace the image with a download link
258+
const container = e.target.parentElement;
259+
container.innerHTML = `
260+
<div style="padding: 48px;">
261+
<h3>🖼️ Image Document</h3>
262+
<p>Unable to display this image.</p>
263+
<p>
264+
<a href="${presignedUrl}" target="_blank" rel="noopener noreferrer"
265+
style="display: inline-block; padding: 12px 24px; background-color: #0073bb;
266+
color: white; text-decoration: none; border-radius: 4px;
267+
font-weight: bold; margin: 10px;">
268+
📥 Download Image
269+
</a>
270+
</p>
271+
</div>
272+
`;
273+
}}
274+
/>
275+
</Box>
276+
</Box>
277+
);
278+
}
279+
242280
// For Excel and Docx files, provide download link since browsers can't display them inline
243281
if (fileType === 'excel' || fileType === 'docx') {
244282
const fileTypeName = fileType === 'excel' ? 'Excel' : 'Word';

0 commit comments

Comments
 (0)