Skip to content

Commit

Permalink
#185 - Documents uploaded with a folder path will download with their…
Browse files Browse the repository at this point in the history
… full folder path for a filename
  • Loading branch information
mfriesen committed Nov 11, 2023
1 parent 77f497b commit 8510f2e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import com.amazonaws.services.lambda.runtime.LambdaLogger;
import com.formkiq.aws.dynamodb.DynamoDbConnectionBuilder;
import com.formkiq.aws.dynamodb.model.DocumentItem;
import com.formkiq.aws.dynamodb.objects.Strings;
import com.formkiq.aws.s3.PresignGetUrlConfig;
import com.formkiq.aws.s3.S3Service;
import com.formkiq.aws.services.lambda.ApiAuthorization;
Expand Down Expand Up @@ -148,13 +149,16 @@ private URL getS3Url(final LambdaLogger logger, final ApiAuthorization authoriza

S3Service s3Service = awsservice.getExtension(S3Service.class);

String filename = Strings.getFilename(item.getPath());
PresignGetUrlConfig config =
new PresignGetUrlConfig().contentDispositionByPath(item.getPath(), inline);
new PresignGetUrlConfig().contentDispositionByPath(filename, inline);

if (contentType == null || contentType.equals(item.getContentType())) {

logger.log("Found default format " + contentType + " for siteId: " + siteId + " documentId: "
+ documentId);
if (awsservice.debug()) {
logger.log("Found default format " + contentType + " for siteId: " + siteId
+ " documentId: " + documentId);
}

config.contentType(item.getContentType());
String s3key = createS3Key(siteId, documentId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.net.URI;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
Expand Down Expand Up @@ -81,7 +82,9 @@ public void testHandleGetDocumentContent01() throws Exception {
setPathParameter(event, "documentId", documentId);
addHeader(event, "Content-Type", contentType);

String filename = "file_" + UUID.randomUUID() + ".pdf";
DocumentItemDynamoDb item = new DocumentItemDynamoDb(documentId, new Date(), userId);
item.setPath("/somepath/" + filename);
if ("text/plain".equals(contentType)) {
item.setContentType(contentType);
}
Expand All @@ -101,6 +104,9 @@ public void testHandleGetDocumentContent01() throws Exception {
"\"headers\":" + GsonUtil.getInstance().toJson(m.get("headers")));
ApiUrlResponse resp = fromJson(m.get("body"), ApiUrlResponse.class);

URI uri = new URI(resp.getUrl());
assertTrue(uri.getQuery().contains("filename=\"" + filename + "\""));

assertTrue(resp.getUrl().contains("X-Amz-Algorithm=AWS4-HMAC-SHA256"));
assertTrue(resp.getUrl().contains("X-Amz-Expires=172800"));
assertTrue(resp.getUrl().contains(AWS_REGION.toString()));
Expand Down

0 comments on commit 8510f2e

Please sign in to comment.