Skip to content

Commit

Permalink
Add mime-type file during the S3 upload (#6)
Browse files Browse the repository at this point in the history
Co-authored-by: Federico Rispo <[email protected]>
  • Loading branch information
federicorispo and federicorispo authored May 3, 2021
1 parent 6ae9204 commit 145fd84
Showing 1 changed file with 13 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -102,17 +102,19 @@ public void execute() throws MojoExecutionException {
keyUpload(amazonS3, keyIfNull(), new File(path));
}
}

private void keyUpload(AmazonS3 amazonS3, String keyName, File file) throws MojoExecutionException {
try (InputStream inputStream = new FileInputStream(file)) {
ObjectMetadata objectMetadata = new ObjectMetadata();
objectMetadata.setContentLength(file.length());

PutObjectRequest putObjectRequest = new PutObjectRequest(bucket, keyName, inputStream, objectMetadata);
amazonS3.putObject(putObjectRequest);
} catch (IOException e) {
throw new MojoExecutionException("Failed to upload mojo",e);
}
/**
* Uploads the given file to the path given by {@code keyName} on the configured {@link #bucket}. Note that the
* ObjectMetadata objectMetadata = new ObjectMetadata(); content-length and content-type of the uploaded file will
* be inferred by the AWS SDK's implementation.
*
* @param amazonS3 the API object to use for the upload
* @param keyName the path in the bucket where the given file will be stored at
* @param file the file to upload
* @see AmazonS3#putObject(String, String, File)
*/
private void keyUpload(AmazonS3 amazonS3, String keyName, File file) {
PutObjectRequest putObjectRequest = new PutObjectRequest(bucket, keyName, file);
amazonS3.putObject(putObjectRequest);
}

private List<String> findFilesToUpload(String filePath) {
Expand Down

0 comments on commit 145fd84

Please sign in to comment.