mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-09-25 06:58:39 +00:00
perform upload to amazon in separate thread
This commit is contained in:
+9
-4
@@ -96,6 +96,11 @@ public class CompetitorsResource extends AbstractSailingServerResource {
|
||||
return Response.ok(json, MediaType.APPLICATION_JSON).build();
|
||||
}
|
||||
|
||||
//
|
||||
// example for testing upload:
|
||||
// $ curl -v -H "Content-Type:image/jpeg" \
|
||||
// --data-binary @<path-to-local-jpg> \
|
||||
// http://127.0.0.1:8888/sailingserver/api/v1/competitors/<competitor-id>/image
|
||||
@POST
|
||||
@Consumes({ "image/jpeg", "image/png" })
|
||||
@Path("{competitor-id}/image")
|
||||
@@ -111,11 +116,11 @@ public class CompetitorsResource extends AbstractSailingServerResource {
|
||||
.entity("Could not find competitor with id " + competitorId).type(MediaType.TEXT_PLAIN).build());
|
||||
}
|
||||
|
||||
String fileExtension = null;
|
||||
String fileExtension = "";
|
||||
if (fileType.equals("image/jpeg")) {
|
||||
fileExtension += ".jpg";
|
||||
} else {
|
||||
fileExtension += ".png";
|
||||
fileExtension = ".jpg";
|
||||
} else if (fileType.equals("image/png")) {
|
||||
fileExtension = ".png";
|
||||
}
|
||||
|
||||
URI imageUri;
|
||||
|
||||
+15
-10
@@ -98,19 +98,24 @@ public class AmazonS3FileStorageServiceImpl implements FileStorageService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public URI storeFile(InputStream is, String fileExtension, long lengthInBytes)
|
||||
public URI storeFile(final InputStream is, String fileExtension, long lengthInBytes)
|
||||
throws InvalidPropertiesException, OperationFailedException {
|
||||
ObjectMetadata metadata = new ObjectMetadata();
|
||||
final ObjectMetadata metadata = new ObjectMetadata();
|
||||
metadata.setContentLength(lengthInBytes);
|
||||
String key = getKey(fileExtension);
|
||||
PutObjectRequest request = new PutObjectRequest(bucketName.getValue(), key, is, metadata)
|
||||
final String key = getKey(fileExtension);
|
||||
final PutObjectRequest request = new PutObjectRequest(bucketName.getValue(), key, is, metadata)
|
||||
.withCannedAcl(CannedAccessControlList.PublicRead);
|
||||
AmazonS3Client s3Client = createS3Client();
|
||||
try {
|
||||
s3Client.putObject(request);
|
||||
} catch (AmazonClientException e) {
|
||||
throw new OperationFailedException("Could not store file", e);
|
||||
}
|
||||
final AmazonS3Client s3Client = createS3Client();
|
||||
|
||||
new Thread() {
|
||||
public void run() {
|
||||
try {
|
||||
s3Client.putObject(request);
|
||||
} catch (AmazonClientException e) {
|
||||
logger.log(Level.WARNING, "Could not store file", e);
|
||||
}
|
||||
};
|
||||
}.run();
|
||||
URI uri = getUri(key);
|
||||
logger.info("Stored file " + uri);
|
||||
return uri;
|
||||
|
||||
Reference in New Issue
Block a user