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

Handle Zip files on upload #905

Open
wants to merge 10 commits into
base: use-files-directly
Choose a base branch
from
Prev Previous commit
Next Next commit
Move files into a scratch directory before processing
  • Loading branch information
trevorgerhardt committed Nov 3, 2023
commit aac3cea7732e0645f56098904c112665a8543225
Original file line number Diff line number Diff line change
@@ -329,6 +329,8 @@ private OpportunityDatasetUploadStatus createOpportunityDataset(Request req, Res
OpportunityDatasetUploadStatus status = new OpportunityDatasetUploadStatus(regionId, sourceName);
addStatusAndRemoveOldStatuses(status);

// TODO should we delete this temporary directory at the end?
final File tmpDirectory = FileUtils.createScratchDirectory();
final List<File> files = new ArrayList<>();
final List<FileItem> fileItems;
final FileStorageFormat uploadFormat;
@@ -338,8 +340,9 @@ private OpportunityDatasetUploadStatus createOpportunityDataset(Request req, Res
// Call remove() rather than get() so that subsequent code will see only string parameters, not the files.
fileItems = formFields.remove("files");
for (var fi : fileItems) {
var dfi = (DiskFileItem) fi;
files.add(dfi.getStoreLocation());
var tmpFile = new File(tmpDirectory, fi.getName());
Files.move(((DiskFileItem) fi).getStoreLocation(), tmpFile);
files.add(tmpFile);
}
uploadFormat = detectUploadFormatAndValidate(files);
parameters = extractStringParameters(formFields);
@@ -541,7 +544,7 @@ private List<Grid> createGridsFromShapefile(List<File> files,
}

// Copy the shapefile component files into a temporary directory with a fixed base name.
File tempDir = Files.createTempDir();
File tempDir = FileUtils.createScratchDirectory();

File shpFile = new File(tempDir, "grid.shp");
Files.copy(filesByExtension.get("SHP"), shpFile);