4949 *
5050 * @author Jiaming LIANG ([email protected] ) 5151 */
52- public class S3DocumentStore implements IDocumentStore {
52+ public class S3DocumentStore implements IDocumentStore < S3UploadConfig > {
5353
5454 /**
5555 * The name of the Amazon S3 Bucket to use.
@@ -71,21 +71,17 @@ public class S3DocumentStore implements IDocumentStore {
7171 * {@inheritDoc}
7272 */
7373 @ Override
74- public IDocumentStoreFile createFromUploadedFile (final InputStream serverFileInputStream , final String keyName ,
75- final long fileSize ) throws IOException {
76-
77- // Creates the request body
78- RequestBody requestBody = RequestBody .of (serverFileInputStream , fileSize );
79-
80- return this .uploadToS3 (requestBody , keyName , fileSize );
74+ public IDocumentStoreFile createFromUploadedFile (final String serverFilePath , final String keyName )
75+ throws IOException {
76+ return this .createFromUploadedFile (serverFilePath , keyName , new S3UploadConfig ());
8177 }
8278
8379 /**
8480 * {@inheritDoc}
8581 */
8682 @ Override
87- public IDocumentStoreFile createFromUploadedFile (final String serverFilePath , final String keyName )
88- throws IOException {
83+ public IDocumentStoreFile createFromUploadedFile (final String serverFilePath , final String keyName ,
84+ final S3UploadConfig uploadConfig ) throws IOException {
8985
9086 // Checks the file
9187 File file = new File (serverFilePath );
@@ -96,7 +92,21 @@ public IDocumentStoreFile createFromUploadedFile(final String serverFilePath, fi
9692 // Creates the request body
9793 RequestBody requestBody = RequestBody .of (file );
9894
99- return this .uploadToS3 (requestBody , keyName , file .length ());
95+ return this .uploadToS3 (requestBody , keyName , file .length (), uploadConfig );
96+
97+ }
98+
99+ /**
100+ * {@inheritDoc}
101+ */
102+ @ Override
103+ public IDocumentStoreFile createFromUploadedFile (final InputStream serverFileInputStream , final String keyName ,
104+ final long fileSize ) throws IOException {
105+
106+ // Creates the request body
107+ RequestBody requestBody = RequestBody .of (serverFileInputStream , fileSize );
108+
109+ return this .uploadToS3 (requestBody , keyName , fileSize , new S3UploadConfig ());
100110 }
101111
102112 /**
@@ -251,16 +261,19 @@ private String extractKeyNameWithoutPrefix(final String keyNameWithPrefix) {
251261 * @param requestBody the request body to put.
252262 * @param keyName the key name of the file.
253263 * @param fileSize the size of the file.
264+ * @param uploadConfig additional upload configuration options.
254265 *
255266 * @return the document store file.
256267 */
257- private IDocumentStoreFile uploadToS3 (final RequestBody requestBody , final String keyName , final long fileSize ) {
268+ private IDocumentStoreFile uploadToS3 (final RequestBody requestBody , final String keyName , final long fileSize ,
269+ final S3UploadConfig uploadConfig ) {
258270
259271 // Create the prefixed key name
260272 String prefixedKeyName = this .createKeyNameWithPrefix (keyName );
261273
262274 // Puts the file on Amazon S3
263- PutObjectRequest putObjectRequest = PutObjectRequest .builder ().bucket (this .bucket ).key (prefixedKeyName ).build ();
275+ PutObjectRequest putObjectRequest = PutObjectRequest .builder ().bucket (this .bucket ).key (prefixedKeyName )
276+ .metadata (uploadConfig .getMetadata ()).build ();
264277
265278 this .s3 .putObject (putObjectRequest , requestBody );
266279
0 commit comments