|
@@ -33,11 +33,15 @@ public class ObjectUploadService {
|
|
|
this.endpoint = endpoint;
|
|
this.endpoint = endpoint;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public UploadFileRet putObject(String key, File file, Map<String, String> headers) {
|
|
|
|
|
|
|
+ public UploadFileRet putObject(File file, int channelId, long userId) {
|
|
|
try {
|
|
try {
|
|
|
- String api = String.format("%s/%s", endpoint, key);
|
|
|
|
|
- HttpRequest.Builder builder = HttpRequest.newBuilder(new URI(api)).version(HttpClient.Version.HTTP_1_1);
|
|
|
|
|
- headers.forEach(builder::header);
|
|
|
|
|
|
|
+ String sha256sum = DigestUtil.sha256sum(file.getAbsolutePath());
|
|
|
|
|
+ String api = String.format("%s/", endpoint);
|
|
|
|
|
+ HttpRequest.Builder builder = HttpRequest.newBuilder(new URI(api))
|
|
|
|
|
+ .version(HttpClient.Version.HTTP_1_1)
|
|
|
|
|
+ .header("x-content-sha256sum", sha256sum)
|
|
|
|
|
+ .header("x-channel-id", channelId+"")
|
|
|
|
|
+ .header("x-user-id", userId+"");
|
|
|
|
|
|
|
|
HttpRequest httpRequest = builder.PUT(HttpRequest.BodyPublishers.ofFile(Path.of(file.getAbsolutePath()))).build();
|
|
HttpRequest httpRequest = builder.PUT(HttpRequest.BodyPublishers.ofFile(Path.of(file.getAbsolutePath()))).build();
|
|
|
HttpResponse<String> httpResponse = httpClient.send(httpRequest, HttpResponse.BodyHandlers.ofString());
|
|
HttpResponse<String> httpResponse = httpClient.send(httpRequest, HttpResponse.BodyHandlers.ofString());
|
|
@@ -49,20 +53,17 @@ public class ObjectUploadService {
|
|
|
return null;
|
|
return null;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public UploadFileRet putObject(String key, InputStream inputStream, Map<String, String> headers) {
|
|
|
|
|
|
|
+ public UploadFileRet putObject(InputStream inputStream, int channelId, int userId) {
|
|
|
try {
|
|
try {
|
|
|
- String api = String.format("%s/%s", endpoint, key);
|
|
|
|
|
- HttpRequest.Builder builder = HttpRequest.newBuilder(new URI(api)).version(HttpClient.Version.HTTP_1_1);
|
|
|
|
|
- headers.forEach(builder::header);
|
|
|
|
|
|
|
+ String api = String.format("%s/", endpoint);
|
|
|
|
|
+ HttpRequest.Builder builder = HttpRequest.newBuilder(new URI(api))
|
|
|
|
|
+ .version(HttpClient.Version.HTTP_1_1)
|
|
|
|
|
+ .header("x-content-sha256sum", "1234567890")
|
|
|
|
|
+ .header("x-channel-id", channelId+"")
|
|
|
|
|
+ .header("x-user-id", userId+"");
|
|
|
|
|
|
|
|
BufferedInputStream bis = new BufferedInputStream(inputStream);
|
|
BufferedInputStream bis = new BufferedInputStream(inputStream);
|
|
|
- Supplier<? extends InputStream> streamSupplier = new Supplier<BufferedInputStream>() {
|
|
|
|
|
- @Override
|
|
|
|
|
- public BufferedInputStream get() {
|
|
|
|
|
- return bis;
|
|
|
|
|
- }
|
|
|
|
|
- };
|
|
|
|
|
-
|
|
|
|
|
|
|
+ Supplier<? extends InputStream> streamSupplier = (Supplier<BufferedInputStream>) () -> bis;
|
|
|
HttpRequest httpRequest = builder.PUT(HttpRequest.BodyPublishers.ofInputStream(streamSupplier)).build();
|
|
HttpRequest httpRequest = builder.PUT(HttpRequest.BodyPublishers.ofInputStream(streamSupplier)).build();
|
|
|
HttpResponse<String> httpResponse = httpClient.send(httpRequest, HttpResponse.BodyHandlers.ofString());
|
|
HttpResponse<String> httpResponse = httpClient.send(httpRequest, HttpResponse.BodyHandlers.ofString());
|
|
|
return getResult(httpResponse);
|
|
return getResult(httpResponse);
|
|
@@ -73,8 +74,7 @@ public class ObjectUploadService {
|
|
|
return null;
|
|
return null;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public UploadFileRet postObject(File file, int channelId) {
|
|
|
|
|
- String authToken = "5c34161755e3d8b44e5f165ce1b91ef9";
|
|
|
|
|
|
|
+ public UploadFileRet postObject(File file, int channelId, long userId) {
|
|
|
try {
|
|
try {
|
|
|
String sha256sum = DigestUtil.sha256sum(file.getAbsolutePath());
|
|
String sha256sum = DigestUtil.sha256sum(file.getAbsolutePath());
|
|
|
MultiPartBodyPublisher publisher = new MultiPartBodyPublisher()
|
|
MultiPartBodyPublisher publisher = new MultiPartBodyPublisher()
|
|
@@ -85,7 +85,7 @@ public class ObjectUploadService {
|
|
|
String api = String.format("%s/", endpoint);
|
|
String api = String.format("%s/", endpoint);
|
|
|
HttpRequest httpRequest = HttpRequest.newBuilder(new URI(api))
|
|
HttpRequest httpRequest = HttpRequest.newBuilder(new URI(api))
|
|
|
.version(HttpClient.Version.HTTP_1_1)
|
|
.version(HttpClient.Version.HTTP_1_1)
|
|
|
- .header("Authorization", authToken)
|
|
|
|
|
|
|
+ .header("x-user-id", userId+"")
|
|
|
.header("Content-Type", "multipart/form-data; boundary=" + publisher.getBoundary())
|
|
.header("Content-Type", "multipart/form-data; boundary=" + publisher.getBoundary())
|
|
|
.POST(publisher.build())
|
|
.POST(publisher.build())
|
|
|
.build();
|
|
.build();
|