-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Expand file tree
/
Copy pathImageAttachment.js
More file actions
37 lines (30 loc) · 1.04 KB
/
ImageAttachment.js
File metadata and controls
37 lines (30 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import PropTypes from 'prop-types';
import React from 'react';
import ImageContent from './ImageContent';
import readDataURIToBlob from '../Utils/readDataURIToBlob';
const ImageAttachment = ({ attachment }) => {
let imageURL = attachment.thumbnailUrl || attachment.contentUrl;
// To support Content Security Policy, data URI cannot be used.
// We need to parse the data URI into a blob: URL.
const blob = readDataURIToBlob(imageURL);
if (blob) {
imageURL = URL.createObjectURL(blob);
}
return <ImageContent alt={attachment.name} src={imageURL} />;
};
ImageAttachment.propTypes = {
// Either attachment.contentUrl or attachment.thumbnailUrl must be specified.
attachment: PropTypes.oneOfType([
PropTypes.shape({
contentUrl: PropTypes.string.isRequired,
name: PropTypes.string,
thumbnailUrl: PropTypes.string
}),
PropTypes.shape({
contentUrl: PropTypes.string,
name: PropTypes.string,
thumbnailUrl: PropTypes.string.isRequired
})
]).isRequired
};
export default ImageAttachment;