git-svn-id: https://svn.d4science-ii.research-infrastructures.eu/gcube/trunk/Common/storagehub-client@169675 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
e54686b00f
commit
a181528978
6
pom.xml
6
pom.xml
|
@ -48,7 +48,7 @@
|
|||
<dependency>
|
||||
<groupId>org.glassfish.jersey.core</groupId>
|
||||
<artifactId>jersey-client</artifactId>
|
||||
<version>2.24.1</version>
|
||||
<version>2.13</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.jaxrs</groupId>
|
||||
|
@ -58,12 +58,12 @@
|
|||
<dependency>
|
||||
<groupId>org.glassfish.jersey.media</groupId>
|
||||
<artifactId>jersey-media-json-jackson</artifactId>
|
||||
<version>2.24.1</version>
|
||||
<version>2.13</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.glassfish.jersey.media</groupId>
|
||||
<artifactId>jersey-media-multipart</artifactId>
|
||||
<version>2.24.1</version>
|
||||
<version>2.13</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.ws.rs</groupId>
|
||||
|
|
|
@ -217,18 +217,14 @@ public class DefaultItemManager implements ItemManagerClient {
|
|||
WebTarget myManager = manager.register(MultiPartFeature.class).path(parentId)
|
||||
.path("create").path("FILE");
|
||||
Invocation.Builder builder = myManager.request();
|
||||
|
||||
try (FormDataMultiPart multipart = new FormDataMultiPart()){
|
||||
|
||||
multipart.field("name", fileName);
|
||||
multipart.field("description", description);
|
||||
|
||||
StreamDataBodyPart fileDataBodyPart = new StreamDataBodyPart("file",stream);
|
||||
multipart.bodyPart(fileDataBodyPart);
|
||||
|
||||
String response = builder.post(Entity.entity(multipart, MediaType.MULTIPART_FORM_DATA_TYPE),String.class);
|
||||
return response;
|
||||
}
|
||||
|
||||
FormDataMultiPart multipart = new FormDataMultiPart();
|
||||
|
||||
multipart.field("name", fileName);
|
||||
multipart.field("description", description);
|
||||
multipart.field("file", stream, MediaType.APPLICATION_OCTET_STREAM_TYPE);
|
||||
String response = builder.post(Entity.entity(multipart, MediaType.MULTIPART_FORM_DATA_TYPE),String.class);
|
||||
return response;
|
||||
|
||||
}
|
||||
};
|
||||
|
|
|
@ -63,13 +63,13 @@ public class Items {
|
|||
}*/
|
||||
|
||||
String afi = null;
|
||||
try (InputStream is = new FileInputStream(new File("/home/lucio/Downloads/test5Gb.zip"))){
|
||||
shc.getWSRoot().uploadFile(is, "5g.zip", "descr");
|
||||
InputStream is = new FileInputStream(new File("/home/lucio/Downloads/test5Gb.zip"));
|
||||
shc.getWSRoot().uploadFile(is, "5g.zip", "descr");
|
||||
|
||||
System.out.println(afi);
|
||||
} catch (Exception e) {
|
||||
System.out.println(afi);
|
||||
/*} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}*/
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -12,6 +12,12 @@ import java.util.Calendar;
|
|||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
|
||||
import javax.ws.rs.client.Client;
|
||||
import javax.ws.rs.client.ClientBuilder;
|
||||
import javax.ws.rs.client.Entity;
|
||||
import javax.ws.rs.client.WebTarget;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
|
||||
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
||||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
import org.gcube.common.storagehub.client.StreamDescriptor;
|
||||
|
@ -34,6 +40,9 @@ import org.gcube.common.storagehub.model.items.AbstractFileItem;
|
|||
import org.gcube.common.storagehub.model.items.Item;
|
||||
import org.gcube.common.storagehub.model.query.Queries;
|
||||
import org.gcube.common.storagehub.model.query.Query;
|
||||
import org.glassfish.jersey.client.ClientProperties;
|
||||
import org.glassfish.jersey.media.multipart.FormDataMultiPart;
|
||||
import org.glassfish.jersey.media.multipart.MultiPartFeature;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
|
@ -92,17 +101,21 @@ public class TestCall {
|
|||
|
||||
@Test
|
||||
public void upload() throws Exception{
|
||||
final ItemManagerClient client = AbstractPlugin.item().at(new URI("http://workspace-repository1-d.d4science.org:8080/storagehub")).build();
|
||||
//final ItemManagerClient client = AbstractPlugin.item().at(new URI("http://workspace-repository1-d.d4science.org:8080/storagehub")).build();
|
||||
|
||||
try (InputStream is = new FileInputStream(new File("/home/lucio/Downloads/test5Gb.zip"))){
|
||||
|
||||
client.uploadFile(is, "bc1c9525-43f7-4565-b5ea-0a0f9d7853a0", "5gb.zip", "description");
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
Client client = ClientBuilder.newClient();
|
||||
client.register(MultiPartFeature.class).property(ClientProperties.CHUNKED_ENCODING_SIZE, 0);
|
||||
WebTarget target = client.target("http://workspace-repository1-d.d4science.org/storagehub/workspace/items/bc1c9525-43f7-4565-b5ea-0a0f9d7853a0/create/FILE?gcube-token=595ca591-9921-423c-bfca-f8be19f05882-98187548");
|
||||
|
||||
FormDataMultiPart multipart = new FormDataMultiPart();
|
||||
|
||||
multipart.field("name", "5gb.zip");
|
||||
multipart.field("description", "description");
|
||||
multipart.field("file", new FileInputStream("/home/lucio/Downloads/test5Gb.zip"), MediaType.APPLICATION_OCTET_STREAM_TYPE);
|
||||
|
||||
target.request().post(Entity.entity(multipart, MediaType.MULTIPART_FORM_DATA));
|
||||
|
||||
//client.uploadFile(new FileInputStream("/home/lucio/Downloads/test5Gb.zip"), "bc1c9525-43f7-4565-b5ea-0a0f9d7853a0", "5gb.zip", "description");
|
||||
|
||||
System.in.read();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue