Skip to content

Commit

Permalink
Adding x-amz-tagging tag in direct upload
Browse files Browse the repository at this point in the history
and catching/reporting non-200 status codes, updating version number
  • Loading branch information
qqmyers committed Mar 4, 2020
1 parent 4a51acf commit 14146b3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>DVUploader</groupId>
<artifactId>DVUploader</artifactId>
<version>1.0.8</version>
<version>1.0.9</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
Expand Down
16 changes: 15 additions & 1 deletion src/main/java/org/sead/uploader/dataverse/DVUploader.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,16 @@

import org.apache.commons.codec.binary.Hex;
import org.apache.http.HttpEntity;
import org.apache.http.HttpHeaders;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.config.CookieSpecs;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpPut;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.client.methods.RequestBuilder;
import org.apache.http.client.protocol.HttpClientContext;
import org.apache.http.conn.ssl.NoopHostnameVerifier;
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
Expand Down Expand Up @@ -410,10 +413,18 @@ protected String uploadDatafile(Resource file, String path) {
String storageIdentifier = data.getString("storageIdentifier");

HttpPut httpput = new HttpPut(uploadUrl);


httpput.addHeader("x-amz-tagging", "dv-state=temp");
MessageDigest messageDigest = MessageDigest.getInstance("MD5");

try (InputStream inStream = file.getInputStream(); DigestInputStream digestInputStream = new DigestInputStream(inStream, messageDigest)) {

// This is hte new form for requests - keeping the example but won't update until we can change all
//HttpUriRequest httpput = RequestBuilder.put()
// .setUri(uploadUrl)
// .setHeader("x-amz-tagging", "dv-state=temp")
// .setEntity(new InputStreamEntity(digestInputStream, file.length()))
// .build();
httpput.setEntity(new InputStreamEntity(digestInputStream, file.length()));
CloseableHttpResponse putResponse = httpclient.execute(httpput);
try {
Expand Down Expand Up @@ -508,6 +519,9 @@ protected String uploadDatafile(Resource file, String path) {
} finally {
EntityUtils.consumeQuietly(response.getEntity());
}
} else {
println("Upload failed with status: " + putStatus + " (skipping)");
retry=0;
}

} catch (IOException e) {
Expand Down

0 comments on commit 14146b3

Please sign in to comment.