-
Notifications
You must be signed in to change notification settings - Fork 78
/
Copy pathWrappedStorageBrowser.tsx
52 lines (46 loc) · 1.31 KB
/
WrappedStorageBrowser.tsx
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import React from 'react';
import { uploadData } from 'aws-amplify/storage';
import StorageBrowser from './StorageBrowser';
interface WrappedStorageBrowserProps {
[key: string]: any; // Allow passing all props
}
const WrappedStorageBrowser: React.FC<WrappedStorageBrowserProps> = (props) => {
/**
* Custom uploadData function that adds an S3 tag.
*/
const uploadDataWithTags = async ({ path, data, options }: any) => {
try {
const result = await uploadData({
path,
data,
options: {
metadata: {
'customKey': 'TestCustomKey', // Replace with actual tag key-value pair
},
},
});
console.log('File uploaded successfully with tagging:', result);
return result;
} catch (error) {
console.error('Error uploading file:', error);
throw error;
}
};
return (
<div>
{/* Pass all other props to StorageBrowser */}
<StorageBrowser {...props} />
{/* Custom upload button to call uploadDataWithTags */}
<input
type="file"
onChange={(e) => {
const file = e.target.files?.[0];
if (file) {
uploadDataWithTags({ path: `uploads/${file.name}`, data: file });
}
}}
/>
</div>
);
};
export default WrappedStorageBrowser;