Skip to content
Snippets Groups Projects
Commit f6c3963e authored by Sonia Zorba's avatar Sonia Zorba
Browse files

Supported both multipart and direct stream upload

parent 4dd402ae
No related branches found
No related tags found
No related merge requests found
Pipeline #1594 passed
......@@ -14,6 +14,7 @@ import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import javax.servlet.http.HttpServletRequest;
import javax.xml.bind.DatatypeConverter;
import net.ivoa.xml.uws.v1.ExecutionPhase;
import org.slf4j.Logger;
......@@ -38,42 +39,43 @@ public class PutFileController extends FileController {
@Autowired
private JobDAO jobDAO;
@Autowired
private ListOfFilesDAO listOfFilesDAO;
@PutMapping("/**")
public ResponseEntity<?> putFile(@RequestHeader(value = HttpHeaders.CONTENT_ENCODING, required = false) String contentEncoding,
@RequestParam("file") MultipartFile file,
@RequestParam(value = "jobid", required = false) String jobId) throws IOException, NoSuchAlgorithmException {
@RequestParam(value = "file", required = false) MultipartFile file,
@RequestParam(value = "jobid", required = false) String jobId,
HttpServletRequest request) throws IOException, NoSuchAlgorithmException {
String path = getPath();
String path = getPath();
if (jobId == null) {
LOG.debug("putFile called for path {}", path);
} else {
LOG.debug("putFile called for path {} with jobId {}", path, jobId);
if(!jobDAO.isJobExisting(jobId))
{
return new ResponseEntity<>("Job "+jobId+ " not found", NOT_FOUND);
if (!jobDAO.isJobExisting(jobId)) {
return new ResponseEntity<>("Job " + jobId + " not found", NOT_FOUND);
}
}
Optional<FileInfo> optFileInfo = fileDAO.getFileInfo(path);
if (optFileInfo.isPresent()) {
try (InputStream in = file.getInputStream()) {
try (InputStream in = file != null ? file.getInputStream() : request.getInputStream()) {
FileInfo fileInfo = optFileInfo.get();
if (fileInfo.getAcceptViews() != null && fileInfo.getAcceptViews().contains("urn:list-of-files")) {
storeListOfFiles(fileInfo, in);
} else {
fileInfo.setContentType(file.getContentType());
if (file != null) {
fileInfo.setContentType(file.getContentType());
}
fileInfo.setContentEncoding(contentEncoding);
storeGenericFile(fileInfo, in, jobId);
}
}
return ResponseEntity.ok().build();
} else {
......@@ -120,10 +122,15 @@ public class PutFileController extends FileController {
}
try {
if(jobId != null){
if (jobId != null) {
fileDAO.setBusy(fileInfo.getNodeId(), true);
}
Files.copy(is, file.toPath());
if (fileInfo.getContentType() == null) {
fileInfo.setContentType(Files.probeContentType(file.toPath()));
}
Long fileSize = Files.size(file.toPath());
String md5Checksum = makeMD5Checksum(file);
......@@ -137,13 +144,13 @@ public class PutFileController extends FileController {
}
} catch (IOException | NoSuchAlgorithmException ex) {
if (jobId != null) {
if (jobId != null) {
jobDAO.updateJobPhase(ExecutionPhase.ERROR, jobId);
}
throw ex;
} finally {
if(jobId != null){
fileDAO.setBusy(fileInfo.getNodeId(), false);
if (jobId != null) {
fileDAO.setBusy(fileInfo.getNodeId(), false);
}
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment