use of com.bluenimble.platform.api.ApiStreamSource in project serverless by bluenimble.
the class PutStorageObjectApiServiceSpi method execute.
@Override
public ApiOutput execute(Api api, ApiConsumer consumer, ApiRequest request, ApiResponse response) throws ApiServiceExecutionException {
Storage storage = api.space().feature(Storage.class, provider, request);
String path = (String) request.get(objectParameter);
if (Lang.isNullOrEmpty(path)) {
throw new ApiServiceExecutionException("missing object path parameter '" + objectParameter + "'").status(ApiResponse.BAD_REQUEST);
}
String objectName = null;
StorageObject so = null;
long length = -1;
ApiStreamSource stream = null;
try {
stream = (ApiStreamSource) request.get(streamParameter, Scope.Stream);
if (Lang.isNullOrEmpty(stream.name())) {
objectName = Lang.UUID(20);
}
so = findFolder(storage.root(), this.folder).add(stream, objectName, true);
length = so.length();
} catch (StorageException e) {
throw new ApiServiceExecutionException(e.getMessage(), e);
}
return new JsonApiOutput((JsonObject) new JsonObject().set(StorageObject.Fields.Name, so.name()).set(StorageObject.Fields.Timestamp, Lang.toUTC(so.timestamp())).set(StorageObject.Fields.Length, length));
}
Aggregations