From 14eda4f46efaf7566a93eeeb88ddbdaba8964b3b Mon Sep 17 00:00:00 2001 From: "miriam.baglioni" Date: Wed, 5 Aug 2020 14:18:25 +0200 Subject: [PATCH] added method to try to put inputstream to zenodo --- .../dnetlib/dhp/oa/graph/dump/APIClient.java | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/dhp-workflows/dhp-graph-mapper/src/main/java/eu/dnetlib/dhp/oa/graph/dump/APIClient.java b/dhp-workflows/dhp-graph-mapper/src/main/java/eu/dnetlib/dhp/oa/graph/dump/APIClient.java index 59f92d885..03bea5477 100644 --- a/dhp-workflows/dhp-graph-mapper/src/main/java/eu/dnetlib/dhp/oa/graph/dump/APIClient.java +++ b/dhp-workflows/dhp-graph-mapper/src/main/java/eu/dnetlib/dhp/oa/graph/dump/APIClient.java @@ -97,6 +97,28 @@ public class APIClient implements Serializable { return -1; } + public int uploadIS(InputStream is, String file_name){ + OkHttpClient httpClient = new OkHttpClient(); + + Request request = new Request.Builder() + .url(bucket + "/" + file_name) + .addHeader("Content-Type", "application/zip") // add request headers + .addHeader("Authorization", "Bearer " + access_token) + .put(InputStreamRequestBody.create(MEDIA_TYPE_ZIP, is)) + .build(); + + try (Response response = httpClient.newCall(request).execute()) { + if (!response.isSuccessful()) + throw new IOException("Unexpected code " + response + response.body().string()); + return response.code(); + } catch (IOException e) { + e.printStackTrace(); + + } + + return -1; + } + public int sendMretadata(String metadata) throws IOException { OkHttpClient httpClient = new OkHttpClient();