forked from taskadapter/redmine-java-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgni.patch
More file actions
107 lines (99 loc) · 4.14 KB
/
gni.patch
File metadata and controls
107 lines (99 loc) · 4.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
From dd138b0d5a0dd247a62f594837a03b4cfb0a4a89 Mon Sep 17 00:00:00 2001
From: RaphaelTocea <rgalerme@Tera>
Date: Tue, 8 Sep 2015 18:43:18 +0200
Subject: [PATCH] patch for upload
---
build.gradle | 2 +-
.../com/taskadapter/redmineapi/AttachmentManager.java | 11 +++++++----
.../com/taskadapter/redmineapi/internal/Transport.java | 15 +++++++++++++++
3 files changed, 23 insertions(+), 5 deletions(-)
diff --git a/build.gradle b/build.gradle
index f61fa15..0e0611f 100644
--- a/build.gradle
+++ b/build.gradle
@@ -8,7 +8,7 @@ apply plugin: 'signing'
apply plugin: 'eclipse'
group = 'com.taskadapter'
-version = '2.4.0'
+version = '2.4.1'
sourceCompatibility = 1.6
targetCompatibility = 1.6
diff --git a/src/main/java/com/taskadapter/redmineapi/AttachmentManager.java b/src/main/java/com/taskadapter/redmineapi/AttachmentManager.java
index 0c5f362..c203cd4 100644
--- a/src/main/java/com/taskadapter/redmineapi/AttachmentManager.java
+++ b/src/main/java/com/taskadapter/redmineapi/AttachmentManager.java
@@ -58,6 +58,9 @@ public class AttachmentManager {
return attach;
}
+
+
+
/**
* Uploads an attachment.
*
@@ -77,7 +80,7 @@ public class AttachmentManager {
byte[] content) throws RedmineException, IOException {
final InputStream is = new ByteArrayInputStream(content);
try {
- return uploadAttachment(fileName, contentType, is);
+ return uploadAttachment(fileName, contentType, is, content.length);
} finally {
try {
is.close();
@@ -104,7 +107,7 @@ public class AttachmentManager {
throws RedmineException, IOException {
final InputStream is = new FileInputStream(content);
try {
- return uploadAttachment(content.getName(), contentType, is);
+ return uploadAttachment(content.getName(), contentType, is, (int) content.length());
} finally {
is.close();
}
@@ -128,12 +131,12 @@ public class AttachmentManager {
* reading errors and transport errors.
*/
public Attachment uploadAttachment(String fileName, String contentType,
- InputStream content) throws RedmineException, IOException {
+ InputStream content, int size) throws RedmineException, IOException {
final InputStream wrapper = new MarkedInputStream(content,
"uploadStream");
final String token;
try {
- token = transport.upload(wrapper);
+ token = transport.upload(wrapper, size);
final Attachment result = AttachmentFactory.create();
result.setToken(token);
result.setContentType(contentType);
diff --git a/src/main/java/com/taskadapter/redmineapi/internal/Transport.java b/src/main/java/com/taskadapter/redmineapi/internal/Transport.java
index 25679a1..dbb71c9 100644
--- a/src/main/java/com/taskadapter/redmineapi/internal/Transport.java
+++ b/src/main/java/com/taskadapter/redmineapi/internal/Transport.java
@@ -67,6 +67,7 @@ import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import org.apache.http.entity.FileEntity;
public final class Transport {
private static final Map<Class<?>, EntityConfig<?>> OBJECT_CONFIGS = new HashMap<Class<?>, EntityConfig<?>>();
@@ -460,6 +461,20 @@ public final class Transport {
}
}
+
+
+ public String upload(InputStream content, int size) throws RedmineException {
+ final URI uploadURI = getURIConfigurator().getUploadURI();
+ final HttpPost request = new HttpPost(uploadURI);
+ final AbstractHttpEntity entity = new InputStreamEntity(content, size);
+ /* Content type required by a Redmine */
+ entity.setContentType("application/octet-stream");
+ request.setEntity(entity);
+
+ final String result = send(request);
+ return parseResponse(result, "upload", RedmineJSONParser.UPLOAD_TOKEN_PARSER);
+ }
+
public static class ResultsWrapper<T> {
final private Integer totalFoundOnServer;
final private List<T> results;
--
2.1.4