use of com.bluenimble.platform.storage.StorageException in project serverless by bluenimble.
the class GetStorageObjectApiServiceSpi method getObject.
private ApiOutput getObject(Api api, ApiRequest request) throws ApiServiceExecutionException {
Storage storage = api.space().feature(Storage.class, provider, request);
String path = (String) request.get(objectParameter);
if (Lang.isNullOrEmpty(path)) {
throw new ApiServiceExecutionException("object path not found. Missing request parameter '" + objectParameter + "'").status(ApiResponse.BAD_REQUEST);
}
ApiOutput output;
try {
StorageObject object = findFolder(storage.root(), this.folder).get(path);
output = object.toOutput(null, (String) request.get(Spec.As), MediaTypeUtils.getMediaForFile((String) request.get(Spec.Type)));
} catch (StorageException e) {
throw new ApiServiceExecutionException(e.getMessage(), e);
}
if (output == null) {
throw new ApiServiceExecutionException("object " + this.folder + Lang.SLASH + path + " not found").status(ApiResponse.BAD_REQUEST);
}
request.set(Output, output);
return output;
}
Aggregations