Commit f6c3963e authored by Sonia Zorba's avatar Sonia Zorba
Browse files

Supported both multipart and direct stream upload

parent 4dd402ae
Loading
Loading
Loading
Loading
Loading
+22 −15
Original line number Diff line number Diff line
@@ -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;
@@ -44,8 +45,9 @@ public class PutFileController extends FileController {

    @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();

@@ -54,8 +56,7 @@ public class PutFileController extends FileController {
        } else {
            LOG.debug("putFile called for path {} with jobId {}", path, jobId);

            if(!jobDAO.isJobExisting(jobId))
            {
            if (!jobDAO.isJobExisting(jobId)) {
                return new ResponseEntity<>("Job " + jobId + " not found", NOT_FOUND);
            }
        }
@@ -63,17 +64,18 @@ public class PutFileController extends FileController {
        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 {
                    if (file != null) {
                        fileInfo.setContentType(file.getContentType());
                    }
                    fileInfo.setContentEncoding(contentEncoding);
                    storeGenericFile(fileInfo, in, jobId);
                }

            }
            return ResponseEntity.ok().build();
        } else {
@@ -124,6 +126,11 @@ public class PutFileController extends FileController {
                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);