Skip to content

Commit

Permalink
NIFI-7594 In HandleHttpRequest deleting multipart file resources afte…
Browse files Browse the repository at this point in the history
…r processing.

This closes apache#4379.

Signed-off-by: Peter Turcsanyi <turcsanyi@apache.org>
  • Loading branch information
tpalfy authored and driesva committed Mar 19, 2021
1 parent f04dde2 commit 947c7b6
Showing 1 changed file with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -640,8 +640,9 @@ public void onTrigger(final ProcessContext context, final ProcessSession session
final int readBufferSize = context.getProperty(MULTIPART_READ_BUFFER_SIZE).asDataSize(DataUnit.B).intValue();
String tempDir = System.getProperty("java.io.tmpdir");
request.setAttribute(Request.MULTIPART_CONFIG_ELEMENT, new MultipartConfigElement(tempDir, requestMaxSize, requestMaxSize, readBufferSize));
List<Part> parts = null;
try {
List<Part> parts = ImmutableList.copyOf(request.getParts());
parts = ImmutableList.copyOf(request.getParts());
int allPartsCount = parts.size();
final String contextIdentifier = UUID.randomUUID().toString();
for (int i = 0; i < allPartsCount; i++) {
Expand All @@ -666,6 +667,16 @@ public void onTrigger(final ProcessContext context, final ProcessSession session
} catch (IOException | ServletException | IllegalStateException e) {
handleFlowContentStreamingError(session, container, request, Optional.absent(), e);
return;
} finally {
if (parts != null) {
for (Part part : parts) {
try {
part.delete();
} catch (Exception e) {
getLogger().error("Couldn't delete underlying storage for {}", new Object[]{part}, e);
}
}
}
}
} else {
FlowFile flowFile = session.create();
Expand Down

0 comments on commit 947c7b6

Please sign in to comment.