Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow 4GB file uploads #3166

Merged
merged 9 commits into from
Mar 26, 2024
8 changes: 7 additions & 1 deletion packages/client/hmi-client/docker/default.conf
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,13 @@ server {
server_name _;

# max file size. Should be kept in sync with the value in application.properties
client_max_body_size 1024M;
client_max_body_size 4096M;

# disable buffering of response bodies to a temporary file
proxy_buffering off;

# disable buffering of request bodies to a temporary file
proxy_request_buffering off;

access_log /var/log/nginx/access.log combined_no_query;
add_header X-Frame-Options SAMEORIGIN;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import co.elastic.clients.elasticsearch._types.query_dsl.TermsQuery;
import co.elastic.clients.elasticsearch._types.query_dsl.TermsQueryField;
import com.fasterxml.jackson.databind.JsonNode;
import com.google.common.collect.ImmutableList;
import com.google.common.math.Quantiles;
import com.google.common.math.Stats;
import io.swagger.v3.oas.annotations.Operation;
Expand Down Expand Up @@ -44,13 +43,8 @@
import software.uncharted.terarium.hmiserver.proxies.jsdelivr.JsDelivrProxy;
import software.uncharted.terarium.hmiserver.security.Roles;
import software.uncharted.terarium.hmiserver.service.data.DatasetService;
import ucar.ma2.Array;
import ucar.nc2.Attribute;
import ucar.nc2.NetcdfFile;
import ucar.nc2.NetcdfFiles;

import java.io.IOException;
import java.io.StringReader;
import java.io.*;
import java.nio.charset.StandardCharsets;
import java.util.*;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -209,7 +203,7 @@ private Optional<Dataset> extractColumnsAsNeededAndSave(final Optional<Dataset>
for(final String filename : dataset.get().getFileNames()) {
if (!filename.endsWith(".nc")) {
try {
final List<List<String>> csv = getCSVFile(filename, dataset.get().getId());
final List<List<String>> csv = getCSVFile(filename, dataset.get().getId(), 1);
if (csv == null || csv.isEmpty()) {
continue;
}
Expand Down Expand Up @@ -284,15 +278,14 @@ ResponseEntity<Dataset> updateDataset(
@ApiResponse(responseCode = "500", description = "There was an issue retrieving the dataset from the data store", content = @Content)
})
public ResponseEntity<CsvAsset> getCsv(
@PathVariable("id") final UUID datasetId,
@RequestParam("filename") final String filename,
@RequestParam(name = "limit", defaultValue = "-1", required = false) final Integer limit // -1 means no
// limit
@PathVariable("id") final UUID datasetId,
@RequestParam("filename") final String filename,
@RequestParam(name = "limit", defaultValue = "" + DEFAULT_CSV_LIMIT, required = false) final Integer limit
bigglesandginger marked this conversation as resolved.
Show resolved Hide resolved
) {

final List<List<String>> csv;
try {
csv = getCSVFile(filename, datasetId);
csv = getCSVFile(filename, datasetId, limit);
if(csv == null){
final String error = "Unable to get CSV";
log.error(error);
Expand Down Expand Up @@ -326,7 +319,7 @@ public ResponseEntity<CsvAsset> getCsv(
return ResponseEntity.ok(csvAsset);
}

private List<List<String>> getCSVFile(final String filename, final UUID datasetId) throws IOException {
private List<List<String>> getCSVFile(final String filename, final UUID datasetId, final Integer limit) throws IOException {
String rawCSV = "";
final CloseableHttpClient httpclient = HttpClients.custom()
.disableRedirectHandling()
Expand All @@ -339,7 +332,17 @@ private List<List<String>> getCSVFile(final String filename, final UUID datasetI
final PresignedURL presignedURL = url.get();
final HttpGet get = new HttpGet(Objects.requireNonNull(presignedURL).getUrl());
final HttpResponse response = httpclient.execute(get);
rawCSV = IOUtils.toString(response.getEntity().getContent(), StandardCharsets.UTF_8);
BufferedReader reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent(), "utf-8"));

String line = null;
Integer count = 0;
while ((line = reader.readLine()) != null) {
if (limit > 0 && count > limit) {
break;
}
rawCSV += line + '\n';
count++;
}

final List<List<String>> csv;
csv = csvToRecords(rawCSV);
Expand Down
4 changes: 2 additions & 2 deletions packages/server/src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ server.http2.enabled=true
spring.jackson.default-property-inclusion=NON_NULL
spring.jackson.mapper.ACCEPT_CASE_INSENSITIVE_ENUMS=true

spring.servlet.multipart.max-file-size=1GB
spring.servlet.multipart.max-request-size=1GB
spring.servlet.multipart.max-file-size=4GB
spring.servlet.multipart.max-request-size=4GB

logging.level.org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver=ERROR
#swagger configuration
Expand Down
Loading