Skip to content

Commit

Permalink
set content-disposition in s3 object metadata on archived recording u…
Browse files Browse the repository at this point in the history
…pload
  • Loading branch information
andrewazores committed Jan 12, 2024
1 parent 6f6d316 commit 979bbc3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
10 changes: 10 additions & 0 deletions src/main/java/io/cryostat/recordings/RecordingHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,11 @@ public String saveRecording(ActiveRecording recording) throws Exception {
}

public String saveRecording(ActiveRecording recording, Instant expiry) throws Exception {
return saveRecording(recording, null, expiry);
}

public String saveRecording(ActiveRecording recording, String savename, Instant expiry)
throws Exception {
// AWS object key name guidelines advise characters to avoid (% so we should not pass url
// encoded characters)
String transformedAlias =
Expand All @@ -441,6 +446,9 @@ public String saveRecording(ActiveRecording recording, Instant expiry) throws Ex
clock.now().truncatedTo(ChronoUnit.SECONDS).toString().replaceAll("[-:]+", "");
String filename =
String.format("%s_%s_%s.jfr", transformedAlias, recording.name, timestamp);
if (StringUtils.isBlank(savename)) {
savename = filename;
}
int mib = 1024 * 1024;
String key = archivedRecordingKey(recording.target.jvmId, filename);
String multipartId = null;
Expand All @@ -453,6 +461,8 @@ public String saveRecording(ActiveRecording recording, Instant expiry) throws Ex
.bucket(archiveBucket)
.key(key)
.contentType(JFR_MIME)
.contentDisposition(
String.format("attachment; filename=\"%s\"", savename))
.tagging(createActiveRecordingTagging(recording, expiry));
if (expiry != null && expiry.isAfter(Instant.now())) {
builder = builder.expires(expiry);
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/io/cryostat/recordings/Recordings.java
Original file line number Diff line number Diff line change
Expand Up @@ -965,11 +965,13 @@ public Response createAndRedirectPresignedDownload(@RestPath long id) throws Exc
if (recording == null) {
throw new NotFoundException();
}
String savename = recording.name;
String filename =
recordingHelper.saveRecording(
recording, Instant.now().plusSeconds(60)); // TODO make expiry configurable
recording,
savename,
Instant.now().plusSeconds(60)); // TODO make expiry configurable
String encodedKey = recordingHelper.encodedKey(recording.target.jvmId, filename);
String savename = recording.name;
if (!savename.endsWith(".jfr")) {
savename += ".jfr";
}
Expand Down

0 comments on commit 979bbc3

Please sign in to comment.