revert commit for uploading files from the ui
@@ -43,6 +43,7 @@ import org.springframework.stereotype.Component;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
+import java.nio.file.AccessDeniedException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
@@ -70,7 +71,6 @@ import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
-import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
@@ -505,9 +505,10 @@ public class FeedRestController {
throw new IOException("Unable to upload file with empty dropzone and file");
}
File tempTarget = File.createTempFile("kylo-upload", "");
+ String fileName = "";
try {
Generex fileNameGenerator = new Generex(regexFileFilter);
- String fileName = fileNameGenerator.random();
+ fileName = fileNameGenerator.random();
// Cleanup oddball characters generated by generex
fileName = fileName.replaceAll("[^A-Za-z0-9\\.\\_\\+\\%\\-\\|]+", "\\.");
@@ -521,14 +522,24 @@ public class FeedRestController {
Files.move(tempTarget.toPath(), dropZoneTarget);
// Set read, write
-
dropZoneFile.setReadable(true);
dropZoneFile.setWritable(true);
+ } catch (AccessDeniedException e) {
+ String errTemplate = "Permission denied attempting to write file [%s] to [%s]. Check with system administrator to ensure this application has write permissions to folder";
+ String err = String.format(errTemplate, fileName, dropzone);
+ log.error(err);
+ throw new InternalServerErrorException(err);
- } catch (IOException e) {
- throw new WebApplicationException(e.getMessage());
+ } catch (Exception e) {
+ String errTemplate = "Unexpected exception writing file [%s] to [%s].";
+ String err = String.format(errTemplate, fileName, dropzone);
+ log.error(err);
+ throw new InternalServerErrorException(err);
}
return Response.ok("").build();
}
+
+
}
+
