mirror of
https://github.com/kestra-io/kestra.git
synced 2025-12-23 21:04:39 -05:00
fix: allow zero-byte file uploads in execution inputs (fixes #8218)
This commit is contained in:
committed by
Loïc Mathieu
parent
e15b53ebb5
commit
f626c85346
@@ -158,11 +158,7 @@ public class FlowInputOutput {
|
||||
File tempFile = File.createTempFile(prefix, fileExtension);
|
||||
try (var inputStream = fileUpload.getInputStream();
|
||||
var outputStream = new FileOutputStream(tempFile)) {
|
||||
long transferredBytes = inputStream.transferTo(outputStream);
|
||||
if (transferredBytes == 0) {
|
||||
sink.error(new KestraRuntimeException("Can't upload file: " + fileUpload.getFilename()));
|
||||
return;
|
||||
}
|
||||
inputStream.transferTo(outputStream);
|
||||
URI from = storageInterface.from(execution, inputId, fileName, tempFile);
|
||||
sink.next(Map.entry(inputId, from.toString()));
|
||||
} finally {
|
||||
|
||||
@@ -2,9 +2,7 @@ package io.kestra.core.runners;
|
||||
|
||||
import io.kestra.core.junit.annotations.KestraTest;
|
||||
import io.kestra.core.models.executions.Execution;
|
||||
import io.kestra.core.models.flows.DependsOn;
|
||||
import io.kestra.core.models.flows.Input;
|
||||
import io.kestra.core.models.flows.Type;
|
||||
import io.kestra.core.models.flows.*;
|
||||
import io.kestra.core.models.flows.input.FileInput;
|
||||
import io.kestra.core.models.flows.input.InputAndValue;
|
||||
import io.kestra.core.models.flows.input.IntInput;
|
||||
@@ -32,6 +30,7 @@ import org.reactivestreams.Publisher;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.File;
|
||||
import java.io.InputStream;
|
||||
import java.net.URI;
|
||||
import java.nio.ByteBuffer;
|
||||
@@ -412,6 +411,40 @@ class FlowInputOutputTest {
|
||||
assertThat(results.get("input")).isEqualTo("default");
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldResolveZeroByteFileUpload() throws java.io.IOException {
|
||||
File tempFile = File.createTempFile("empty", ".txt");
|
||||
tempFile.deleteOnExit();
|
||||
|
||||
io.micronaut.http.multipart.CompletedFileUpload fileUpload = org.mockito.Mockito.mock(io.micronaut.http.multipart.CompletedFileUpload.class);
|
||||
org.mockito.Mockito.when(fileUpload.getInputStream()).thenReturn(new java.io.FileInputStream(tempFile));
|
||||
org.mockito.Mockito.when(fileUpload.getFilename()).thenReturn("empty.txt");
|
||||
org.mockito.Mockito.when(fileUpload.getName()).thenReturn("empty_file");
|
||||
|
||||
Execution execution = Execution.builder()
|
||||
.id(IdUtils.create())
|
||||
.tenantId("unit_test_tenant")
|
||||
.namespace("io.kestra.unittest")
|
||||
.flowId("unittest")
|
||||
.flowRevision(1)
|
||||
.state(new State())
|
||||
.build();
|
||||
|
||||
reactor.core.publisher.Mono<Map<String, Object>> result = flowInputOutput.readExecutionInputs(
|
||||
List.of(
|
||||
io.kestra.core.models.flows.input.FileInput.builder().id("empty_file").type(Type.FILE).build()
|
||||
),
|
||||
Flow.builder().id("unittest").namespace("io.kestra.unittest").build(),
|
||||
execution,
|
||||
reactor.core.publisher.Flux.just(fileUpload)
|
||||
);
|
||||
|
||||
Map<String, Object> outputs = result.block();
|
||||
|
||||
Assertions.assertNotNull(outputs);
|
||||
Assertions.assertTrue(outputs.containsKey("empty_file"));
|
||||
}
|
||||
|
||||
private static class MemoryCompletedPart implements CompletedPart {
|
||||
|
||||
protected final String name;
|
||||
|
||||
Reference in New Issue
Block a user