use of com.haulmont.cuba.core.global.FileStorageException in project cuba by cuba-platform.
the class DesktopFileDescriptorResource method createResource.
@Override
protected void createResource() {
try {
InputStream stream = AppBeans.get(FileLoader.class).openStream(fileDescriptor);
resource = ImageIO.read(stream);
} catch (FileStorageException e) {
throw new RuntimeException(FILE_STORAGE_EXCEPTION_MESSAGE, e);
} catch (IOException e) {
throw new RuntimeException("An error occurred while loading an image.", e);
}
}
use of com.haulmont.cuba.core.global.FileStorageException in project cuba by cuba-platform.
the class FileUploadController method upload.
@RequestMapping(value = "/upload", method = RequestMethod.POST)
public void upload(HttpServletRequest request, HttpServletResponse response) throws IOException {
UserSession userSession = getSession(request, response);
if (userSession == null)
return;
AppContext.setSecurityContext(new SecurityContext(userSession));
try {
InputStream is = request.getInputStream();
if (is == null) {
response.sendError(HttpServletResponse.SC_BAD_REQUEST);
return;
}
FileDescriptor fd = getFileDescriptor(request, response);
if (fd == null)
return;
try {
fileStorage.saveStream(fd, is);
} catch (FileStorageException e) {
log.error("Unable to upload file", e);
response.sendError(e.getType().getHttpStatus());
} finally {
IOUtils.closeQuietly(is);
}
} finally {
AppContext.setSecurityContext(null);
}
}
use of com.haulmont.cuba.core.global.FileStorageException in project cuba by cuba-platform.
the class WebFileUploadField method saveFile.
protected void saveFile(FileDescriptor fileDescriptor) {
switch(mode) {
case MANUAL:
internalValueChangedOnUpload = true;
setValue(fileDescriptor);
internalValueChangedOnUpload = false;
break;
case IMMEDIATE:
try {
fileUploading.putFileIntoStorage(fileId, fileDescriptor);
FileDescriptor committedDescriptor = commitFileDescriptor(fileDescriptor);
setValue(committedDescriptor);
} catch (FileStorageException e) {
log.error("Error has occurred during file saving", e);
}
break;
}
}
Aggregations