40 lines
1.1 KiB
Java
40 lines
1.1 KiB
Java
|
package org.gcube.datatransfer.resolver.services;
|
||
|
|
||
|
import javax.enterprise.context.RequestScoped;
|
||
|
import javax.ws.rs.GET;
|
||
|
import javax.ws.rs.Path;
|
||
|
import javax.ws.rs.PathParam;
|
||
|
import javax.ws.rs.core.Response;
|
||
|
|
||
|
import org.gcube.common.storagehub.client.StreamDescriptor;
|
||
|
import org.gcube.common.storagehub.client.dsl.StorageHubClient;
|
||
|
|
||
|
@Path("shub/{id}")
|
||
|
public class StorageHub {
|
||
|
|
||
|
@RequestScoped
|
||
|
@PathParam("id")
|
||
|
String id;
|
||
|
|
||
|
@GET
|
||
|
@Path("")
|
||
|
public Response download() {
|
||
|
StorageHubClient shc = new StorageHubClient();
|
||
|
StreamDescriptor descriptor = shc.open(id).asFile().download();
|
||
|
|
||
|
return Response
|
||
|
.ok(descriptor.getStream())
|
||
|
.header("content-disposition","attachment; filename = \""+descriptor.getFileName()+"\"").build();
|
||
|
}
|
||
|
|
||
|
@GET
|
||
|
@Path("{version}")
|
||
|
public Response downloadVersion(@PathParam("version") String version) {
|
||
|
StorageHubClient shc = new StorageHubClient();
|
||
|
StreamDescriptor descriptor = shc.open(id).asFile().downloadSpecificVersion(version);
|
||
|
return Response
|
||
|
.ok(descriptor.getStream())
|
||
|
.header("content-disposition","attachment; filename = \""+descriptor.getFileName()+"\"").build();
|
||
|
}
|
||
|
}
|