Skip to content

Commit 14146b3

Browse files
committed
Adding x-amz-tagging tag in direct upload
and catching/reporting non-200 status codes, updating version number
1 parent 4a51acf commit 14146b3

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<modelVersion>4.0.0</modelVersion>
55
<groupId>DVUploader</groupId>
66
<artifactId>DVUploader</artifactId>
7-
<version>1.0.8</version>
7+
<version>1.0.9</version>
88
<properties>
99
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
1010
</properties>

src/main/java/org/sead/uploader/dataverse/DVUploader.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,16 @@
3131

3232
import org.apache.commons.codec.binary.Hex;
3333
import org.apache.http.HttpEntity;
34+
import org.apache.http.HttpHeaders;
3435
import org.apache.http.client.ClientProtocolException;
3536
import org.apache.http.client.config.CookieSpecs;
3637
import org.apache.http.client.config.RequestConfig;
3738
import org.apache.http.client.methods.CloseableHttpResponse;
3839
import org.apache.http.client.methods.HttpGet;
3940
import org.apache.http.client.methods.HttpPost;
4041
import org.apache.http.client.methods.HttpPut;
42+
import org.apache.http.client.methods.HttpUriRequest;
43+
import org.apache.http.client.methods.RequestBuilder;
4144
import org.apache.http.client.protocol.HttpClientContext;
4245
import org.apache.http.conn.ssl.NoopHostnameVerifier;
4346
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
@@ -410,10 +413,18 @@ protected String uploadDatafile(Resource file, String path) {
410413
String storageIdentifier = data.getString("storageIdentifier");
411414

412415
HttpPut httpput = new HttpPut(uploadUrl);
416+
417+
418+
httpput.addHeader("x-amz-tagging", "dv-state=temp");
413419
MessageDigest messageDigest = MessageDigest.getInstance("MD5");
414420

415421
try (InputStream inStream = file.getInputStream(); DigestInputStream digestInputStream = new DigestInputStream(inStream, messageDigest)) {
416-
422+
// This is hte new form for requests - keeping the example but won't update until we can change all
423+
//HttpUriRequest httpput = RequestBuilder.put()
424+
// .setUri(uploadUrl)
425+
// .setHeader("x-amz-tagging", "dv-state=temp")
426+
// .setEntity(new InputStreamEntity(digestInputStream, file.length()))
427+
// .build();
417428
httpput.setEntity(new InputStreamEntity(digestInputStream, file.length()));
418429
CloseableHttpResponse putResponse = httpclient.execute(httpput);
419430
try {
@@ -508,6 +519,9 @@ protected String uploadDatafile(Resource file, String path) {
508519
} finally {
509520
EntityUtils.consumeQuietly(response.getEntity());
510521
}
522+
} else {
523+
println("Upload failed with status: " + putStatus + " (skipping)");
524+
retry=0;
511525
}
512526

513527
} catch (IOException e) {

0 commit comments

Comments
 (0)