use of org.codelibs.fess.exception.StorageException in project fess by codelibs.
the class AdminStorageAction method downloadObject.
public static void downloadObject(final String objectName, final WrittenStreamOut out) {
final FessConfig fessConfig = ComponentUtil.getFessConfig();
final GetObjectArgs args = GetObjectArgs.builder().bucket(fessConfig.getStorageBucket()).object(objectName).build();
try (InputStream in = createClient(fessConfig).getObject(args)) {
out.write(in);
} catch (final Exception e) {
throw new StorageException("Failed to download " + objectName, e);
}
}
use of org.codelibs.fess.exception.StorageException in project fess by codelibs.
the class AdminStorageAction method download.
@Execute
@Secured({ ROLE, ROLE + VIEW })
public ActionResponse download(final String id) {
final String[] values = decodeId(id);
if (StringUtil.isEmpty(values[1])) {
throwValidationError(messages -> messages.addErrorsStorageFileNotFound(GLOBAL), () -> asListHtml(encodeId(values[0])));
}
final StreamResponse response = new StreamResponse(StringUtil.EMPTY);
final String name = values[1];
final String encodedName = URLEncoder.encode(name, Constants.UTF_8_CHARSET).replace("+", "%20");
response.header("Content-Disposition", "attachment; filename=\"" + name + "\"; filename*=utf-8''" + encodedName);
response.header("Pragma", "no-cache");
response.header("Cache-Control", "no-cache");
response.header("Expires", "Thu, 01 Dec 1994 16:00:00 GMT");
response.contentTypeOctetStream();
return response.stream(out -> {
try {
downloadObject(getObjectName(values[0], values[1]), out);
} catch (final StorageException e) {
if (logger.isDebugEnabled()) {
logger.debug("Failed to download {}", values[1], e);
}
throwValidationError(messages -> messages.addErrorsStorageFileDownloadFailure(GLOBAL, values[1]), () -> asListHtml(encodeId(values[0])));
}
});
}
use of org.codelibs.fess.exception.StorageException in project fess by codelibs.
the class AdminStorageAction method deleteObject.
public static void deleteObject(final String objectName) {
try {
final FessConfig fessConfig = ComponentUtil.getFessConfig();
final MinioClient minioClient = createClient(fessConfig);
final RemoveObjectArgs args = RemoveObjectArgs.builder().bucket(fessConfig.getStorageBucket()).object(objectName).build();
minioClient.removeObject(args);
} catch (final Exception e) {
throw new StorageException("Failed to delete " + objectName, e);
}
}
use of org.codelibs.fess.exception.StorageException in project fess by codelibs.
the class AdminStorageAction method uploadObject.
public static void uploadObject(final String objectName, final MultipartFormFile uploadFile) {
try (final InputStream in = uploadFile.getInputStream()) {
final FessConfig fessConfig = ComponentUtil.getFessConfig();
final MinioClient minioClient = createClient(fessConfig);
final PutObjectArgs args = PutObjectArgs.builder().bucket(fessConfig.getStorageBucket()).object(objectName).stream(in, uploadFile.getFileSize(), -1).contentType("application/octet-stream").build();
minioClient.putObject(args);
} catch (final Exception e) {
throw new StorageException("Failed to upload " + objectName, e);
}
}
Aggregations