|
|
@@ -1,458 +0,0 @@
|
|
|
-package cn.reghao.oss.sdk;
|
|
|
-
|
|
|
-import cn.reghao.jutil.jdk.result.WebResult;
|
|
|
-import cn.reghao.jutil.tool.json.JsonConverter;
|
|
|
-import cn.reghao.oss.api.dto.ObjectInfo;
|
|
|
-import cn.reghao.oss.api.dto.ServerInfo;
|
|
|
-import cn.reghao.oss.sdk.model.OssConsoleConfig;
|
|
|
-import cn.reghao.oss.api.dto.media.*;
|
|
|
-import cn.reghao.oss.api.rest.UploadFileRet;
|
|
|
-import com.google.gson.reflect.TypeToken;
|
|
|
-
|
|
|
-import java.io.File;
|
|
|
-import java.lang.reflect.Type;
|
|
|
-import java.net.URI;
|
|
|
-import java.net.URLEncoder;
|
|
|
-import java.net.http.HttpClient;
|
|
|
-import java.net.http.HttpRequest;
|
|
|
-import java.net.http.HttpResponse;
|
|
|
-import java.nio.charset.StandardCharsets;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.Map;
|
|
|
-
|
|
|
-/**
|
|
|
- * @author reghao
|
|
|
- * @date 2024-02-23 21:47:39
|
|
|
- */
|
|
|
-public class OssConsoleClient {
|
|
|
- private final HttpClient httpClient = HttpClient.newBuilder().build();
|
|
|
- private final String endpoint;
|
|
|
- private String token;
|
|
|
-
|
|
|
- public OssConsoleClient(OssConsoleConfig ossConsoleConfig) throws Exception {
|
|
|
- this.endpoint = ossConsoleConfig.getConsoleUrl();
|
|
|
- auth(ossConsoleConfig.getAccessKeyId(), ossConsoleConfig.getAccessKeySecret());
|
|
|
- }
|
|
|
-
|
|
|
- // ****************************************************************************************************************
|
|
|
- // oss-console 认证接口
|
|
|
- // ****************************************************************************************************************
|
|
|
- private void auth(String accessKeyId, String accessKeySecret) throws Exception {
|
|
|
- MultiPartBodyPublisher publisher = new MultiPartBodyPublisher()
|
|
|
- .addPart("accessKeyId", accessKeyId)
|
|
|
- .addPart("accessKeySecret", accessKeySecret);
|
|
|
-
|
|
|
- String api = String.format("%s/api/oss/sdk/key/auth", endpoint);
|
|
|
- HttpRequest httpRequest = HttpRequest.newBuilder(new URI(api))
|
|
|
- .version(HttpClient.Version.HTTP_1_1)
|
|
|
- .header("content-type", "multipart/form-data; boundary=" + publisher.getBoundary())
|
|
|
- .POST(publisher.build())
|
|
|
- .build();
|
|
|
-
|
|
|
- HttpResponse<String> httpResponse = httpClient.send(httpRequest, HttpResponse.BodyHandlers.ofString());
|
|
|
- int statusCode = httpResponse.statusCode();
|
|
|
- String body = httpResponse.body();
|
|
|
- if (statusCode != 200) {
|
|
|
- String errMsg = String.format("%s -> %s", statusCode, body);
|
|
|
- throw new Exception(errMsg);
|
|
|
- }
|
|
|
-
|
|
|
- Type type = new TypeToken<WebResult<String>>(){}.getType();
|
|
|
- WebResult<String> webResult = JsonConverter.jsonToObject(body, type);
|
|
|
- if (webResult.getCode() != 0) {
|
|
|
- String errMsg = String.format("%s - %s", webResult.getCode(), webResult.getMsg());
|
|
|
- throw new Exception(errMsg);
|
|
|
- }
|
|
|
-
|
|
|
- this.token = webResult.getData();
|
|
|
- }
|
|
|
-
|
|
|
- // ****************************************************************************************************************
|
|
|
- // oss-store 相关接口
|
|
|
- // ****************************************************************************************************************
|
|
|
- public ServerInfo getUploadStore(int channelCode) throws Exception {
|
|
|
- String api = String.format("%s/api/oss/sdk/upload/store?channelCode=%s", endpoint, channelCode);
|
|
|
- HttpRequest httpRequest = HttpRequest.newBuilder(new URI(api))
|
|
|
- .header("authorization", "Bearer " + token)
|
|
|
- .version(HttpClient.Version.HTTP_1_1)
|
|
|
- .GET()
|
|
|
- .build();
|
|
|
- HttpResponse<String> httpResponse = httpClient.send(httpRequest, HttpResponse.BodyHandlers.ofString());
|
|
|
- int statusCode = httpResponse.statusCode();
|
|
|
- String body = httpResponse.body();
|
|
|
- if (statusCode != 200) {
|
|
|
- String errMsg = String.format("%s -> %s", statusCode, body);
|
|
|
- throw new Exception(errMsg);
|
|
|
- }
|
|
|
-
|
|
|
- Type type = new TypeToken<WebResult<ServerInfo>>(){}.getType();
|
|
|
- WebResult<ServerInfo> webResult = JsonConverter.jsonToObject(body, type);
|
|
|
- if (webResult.getCode() != 0) {
|
|
|
- String errMsg = String.format("%s - %s", webResult.getCode(), webResult.getMsg());
|
|
|
- throw new Exception(errMsg);
|
|
|
- }
|
|
|
-
|
|
|
- return webResult.getData();
|
|
|
- }
|
|
|
-
|
|
|
- public void setObjectScope(int channelCode, String objectId, int scope) throws Exception {
|
|
|
- Map<String, String> formData = new HashMap<>();
|
|
|
- formData.put("channelCode", channelCode+"");
|
|
|
- formData.put("scope", scope+"");
|
|
|
- formData.put("objectId", objectId);
|
|
|
-
|
|
|
- String api = String.format("%s/api/oss/sdk/object/scope", endpoint);
|
|
|
- HttpRequest httpRequest = HttpRequest.newBuilder(new URI(api))
|
|
|
- .header("authorization", "Bearer " + token)
|
|
|
- .headers("content-type", "application/x-www-form-urlencoded")
|
|
|
- .version(HttpClient.Version.HTTP_1_1)
|
|
|
- .POST(HttpRequest.BodyPublishers.ofString(getFormDataAsString(formData)))
|
|
|
- .build();
|
|
|
- HttpResponse<String> httpResponse = httpClient.send(httpRequest, HttpResponse.BodyHandlers.ofString());
|
|
|
- int statusCode = httpResponse.statusCode();
|
|
|
- String body = httpResponse.body();
|
|
|
- if (statusCode != 200) {
|
|
|
- String errMsg = String.format("%s -> %s", statusCode, body);
|
|
|
- throw new Exception(errMsg);
|
|
|
- }
|
|
|
-
|
|
|
- Type type = new TypeToken<WebResult<String>>(){}.getType();
|
|
|
- WebResult<String> webResult = JsonConverter.jsonToObject(body, type);
|
|
|
- if (webResult.getCode() != 0) {
|
|
|
- String errMsg = String.format("%s - %s", webResult.getCode(), webResult.getMsg());
|
|
|
- throw new Exception(errMsg);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- private String getFormDataAsString(Map<String, String> formData) {
|
|
|
- StringBuilder formBodyBuilder = new StringBuilder();
|
|
|
- for (Map.Entry<String, String> singleEntry : formData.entrySet()) {
|
|
|
- if (formBodyBuilder.length() > 0) {
|
|
|
- formBodyBuilder.append("&");
|
|
|
- }
|
|
|
- formBodyBuilder.append(URLEncoder.encode(singleEntry.getKey(), StandardCharsets.UTF_8));
|
|
|
- formBodyBuilder.append("=");
|
|
|
- formBodyBuilder.append(URLEncoder.encode(singleEntry.getValue(), StandardCharsets.UTF_8));
|
|
|
- }
|
|
|
- return formBodyBuilder.toString();
|
|
|
- }
|
|
|
-
|
|
|
- public void deleteByObjectId(int channelCode, String objectId) throws Exception {
|
|
|
- Map<String, String> formData = new HashMap<>();
|
|
|
- formData.put("channelCode", channelCode+"");
|
|
|
- formData.put("objectId", objectId);
|
|
|
-
|
|
|
- String api = String.format("%s/api/oss/sdk/object/delete/id", endpoint);
|
|
|
- HttpRequest httpRequest = HttpRequest.newBuilder(new URI(api))
|
|
|
- .header("authorization", "Bearer " + token)
|
|
|
- .headers("content-type", "application/x-www-form-urlencoded")
|
|
|
- .version(HttpClient.Version.HTTP_1_1)
|
|
|
- .POST(HttpRequest.BodyPublishers.ofString(getFormDataAsString(formData)))
|
|
|
- .build();
|
|
|
- HttpResponse<String> httpResponse = httpClient.send(httpRequest, HttpResponse.BodyHandlers.ofString());
|
|
|
- int statusCode = httpResponse.statusCode();
|
|
|
- String body = httpResponse.body();
|
|
|
- if (statusCode != 200) {
|
|
|
- String errMsg = String.format("%s -> %s", statusCode, body);
|
|
|
- throw new Exception(errMsg);
|
|
|
- }
|
|
|
-
|
|
|
- Type type = new TypeToken<WebResult<String>>(){}.getType();
|
|
|
- WebResult<String> webResult = JsonConverter.jsonToObject(body, type);
|
|
|
- if (webResult.getCode() != 0) {
|
|
|
- String errMsg = String.format("%s - %s", webResult.getCode(), webResult.getMsg());
|
|
|
- throw new Exception(errMsg);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- public void deleteByObjectUrl(String objectUrl) throws Exception {
|
|
|
- Map<String, String> formData = new HashMap<>();
|
|
|
- formData.put("objectUrl", objectUrl);
|
|
|
-
|
|
|
- String api = String.format("%s/api/oss/sdk/object/delete/url", endpoint);
|
|
|
- HttpRequest httpRequest = HttpRequest.newBuilder(new URI(api))
|
|
|
- .header("authorization", "Bearer " + token)
|
|
|
- .headers("content-type", "application/x-www-form-urlencoded")
|
|
|
- .version(HttpClient.Version.HTTP_1_1)
|
|
|
- .POST(HttpRequest.BodyPublishers.ofString(getFormDataAsString(formData)))
|
|
|
- .build();
|
|
|
- HttpResponse<String> httpResponse = httpClient.send(httpRequest, HttpResponse.BodyHandlers.ofString());
|
|
|
- int statusCode = httpResponse.statusCode();
|
|
|
- String body = httpResponse.body();
|
|
|
- if (statusCode != 200) {
|
|
|
- String errMsg = String.format("%s -> %s", statusCode, body);
|
|
|
- throw new Exception(errMsg);
|
|
|
- }
|
|
|
-
|
|
|
- Type type = new TypeToken<WebResult<String>>(){}.getType();
|
|
|
- WebResult<String> webResult = JsonConverter.jsonToObject(body, type);
|
|
|
- if (webResult.getCode() != 0) {
|
|
|
- String errMsg = String.format("%s - %s", webResult.getCode(), webResult.getMsg());
|
|
|
- throw new Exception(errMsg);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- public ObjectInfo getObjectInfo(int channelCode, String objectId) throws Exception {
|
|
|
- String api = String.format("%s/api/oss/sdk/object/info?channelCode=%s&objectId=%s", endpoint, channelCode, objectId);
|
|
|
- HttpRequest httpRequest = HttpRequest.newBuilder(new URI(api))
|
|
|
- .header("authorization", "Bearer " + token)
|
|
|
- .version(HttpClient.Version.HTTP_1_1)
|
|
|
- .GET()
|
|
|
- .build();
|
|
|
- HttpResponse<String> httpResponse = httpClient.send(httpRequest, HttpResponse.BodyHandlers.ofString());
|
|
|
- int statusCode = httpResponse.statusCode();
|
|
|
- String body = httpResponse.body();
|
|
|
- if (statusCode != 200) {
|
|
|
- throw new Exception(body);
|
|
|
- }
|
|
|
-
|
|
|
- Type type = new TypeToken<WebResult<ObjectInfo>>(){}.getType();
|
|
|
- WebResult<ObjectInfo> webResult = JsonConverter.jsonToObject(body, type);
|
|
|
- if (webResult.getCode() != 0) {
|
|
|
- throw new Exception(webResult.getMsg());
|
|
|
- }
|
|
|
-
|
|
|
- return webResult.getData();
|
|
|
- }
|
|
|
-
|
|
|
- public String getSignedUrl(int channelCode, String objectId) throws Exception {
|
|
|
- String api = String.format("%s/api/oss/sdk/object/url?channelCode=%s&objectId=%s", endpoint, channelCode, objectId);
|
|
|
- HttpRequest httpRequest = HttpRequest.newBuilder(new URI(api))
|
|
|
- .header("authorization", "Bearer " + token)
|
|
|
- .version(HttpClient.Version.HTTP_1_1)
|
|
|
- .GET()
|
|
|
- .build();
|
|
|
- HttpResponse<String> httpResponse = httpClient.send(httpRequest, HttpResponse.BodyHandlers.ofString());
|
|
|
- int statusCode = httpResponse.statusCode();
|
|
|
- String body = httpResponse.body();
|
|
|
- if (statusCode != 200) {
|
|
|
- throw new Exception(body);
|
|
|
- }
|
|
|
-
|
|
|
- Type type = new TypeToken<WebResult<String>>(){}.getType();
|
|
|
- WebResult<String> webResult = JsonConverter.jsonToObject(body, type);
|
|
|
- if (webResult.getCode() != 0) {
|
|
|
- String errMsg = String.format("%s - %s", webResult.getCode(), webResult.getMsg());
|
|
|
- throw new Exception(errMsg);
|
|
|
- }
|
|
|
-
|
|
|
- return webResult.getData();
|
|
|
- }
|
|
|
-
|
|
|
- public String getSignedUrlByUrl(int channelCode, String objectUrl) throws Exception {
|
|
|
- String api = String.format("%s/api/oss/sdk/object/signed_url?channelCode=%s&objectUrl=%s", endpoint, channelCode, objectUrl);
|
|
|
- HttpRequest httpRequest = HttpRequest.newBuilder(new URI(api))
|
|
|
- .header("authorization", "Bearer " + token)
|
|
|
- .version(HttpClient.Version.HTTP_1_1)
|
|
|
- .GET()
|
|
|
- .build();
|
|
|
- HttpResponse<String> httpResponse = httpClient.send(httpRequest, HttpResponse.BodyHandlers.ofString());
|
|
|
- int statusCode = httpResponse.statusCode();
|
|
|
- String body = httpResponse.body();
|
|
|
- if (statusCode != 200) {
|
|
|
- throw new Exception(body);
|
|
|
- }
|
|
|
-
|
|
|
- Type type = new TypeToken<WebResult<String>>(){}.getType();
|
|
|
- WebResult<String> webResult = JsonConverter.jsonToObject(body, type);
|
|
|
- if (webResult.getCode() != 0) {
|
|
|
- String errMsg = String.format("%s - %s", webResult.getCode(), webResult.getMsg());
|
|
|
- throw new Exception(errMsg);
|
|
|
- }
|
|
|
-
|
|
|
- return webResult.getData();
|
|
|
- }
|
|
|
-
|
|
|
- // ****************************************************************************************************************
|
|
|
- // 媒体文件信息相关接口
|
|
|
- // ****************************************************************************************************************
|
|
|
- public VideoInfo getVideoInfo(int channelCode, String objectId) throws Exception {
|
|
|
- String api = String.format("%s/api/oss/sdk/object/video/info?channelCode=%s&objectId=%s", endpoint, channelCode, objectId);
|
|
|
- HttpRequest httpRequest = HttpRequest.newBuilder(new URI(api))
|
|
|
- .header("authorization", "Bearer " + token)
|
|
|
- .version(HttpClient.Version.HTTP_1_1)
|
|
|
- .GET()
|
|
|
- .build();
|
|
|
- HttpResponse<String> httpResponse = httpClient.send(httpRequest, HttpResponse.BodyHandlers.ofString());
|
|
|
- int statusCode = httpResponse.statusCode();
|
|
|
- String body = httpResponse.body();
|
|
|
- if (statusCode != 200) {
|
|
|
- throw new Exception(body);
|
|
|
- }
|
|
|
-
|
|
|
- Type type = new TypeToken<WebResult<VideoInfo>>(){}.getType();
|
|
|
- WebResult<VideoInfo> webResult = JsonConverter.jsonToObject(body, type);
|
|
|
- if (webResult.getCode() != 0) {
|
|
|
- throw new Exception(webResult.getMsg());
|
|
|
- }
|
|
|
-
|
|
|
- return webResult.getData();
|
|
|
- }
|
|
|
-
|
|
|
- public ImageInfo getImageInfo(int channelCode, String objectId) throws Exception {
|
|
|
- String api = String.format("%s/api/oss/sdk/object/image/info?channelCode=%s&objectId=%s", endpoint, channelCode, objectId);
|
|
|
- HttpRequest httpRequest = HttpRequest.newBuilder(new URI(api))
|
|
|
- .header("authorization", "Bearer " + token)
|
|
|
- .headers("content-type", "application/x-www-form-urlencoded")
|
|
|
- .version(HttpClient.Version.HTTP_1_1)
|
|
|
- .GET()
|
|
|
- .build();
|
|
|
- HttpResponse<String> httpResponse = httpClient.send(httpRequest, HttpResponse.BodyHandlers.ofString());
|
|
|
- int statusCode = httpResponse.statusCode();
|
|
|
- String body = httpResponse.body();
|
|
|
- if (statusCode != 200) {
|
|
|
- throw new Exception(body);
|
|
|
- }
|
|
|
-
|
|
|
- Type type = new TypeToken<WebResult<ImageInfo>>(){}.getType();
|
|
|
- WebResult<ImageInfo> webResult = JsonConverter.jsonToObject(body, type);
|
|
|
- if (webResult.getCode() != 0) {
|
|
|
- throw new Exception(webResult.getMsg());
|
|
|
- }
|
|
|
-
|
|
|
- return webResult.getData();
|
|
|
- }
|
|
|
-
|
|
|
- public ConvertedImageInfo getWebpInfo(int channelCode, String objectId) throws Exception {
|
|
|
- Map<String, String> formData = new HashMap<>();
|
|
|
- formData.put("channelCode", ""+channelCode);
|
|
|
- formData.put("objectId", objectId);
|
|
|
-
|
|
|
- String api = String.format("%s/api/oss/sdk/object/image/webp", endpoint);
|
|
|
- HttpRequest httpRequest = HttpRequest.newBuilder(new URI(api))
|
|
|
- .header("authorization", "Bearer " + token)
|
|
|
- .headers("content-type", "application/x-www-form-urlencoded")
|
|
|
- .version(HttpClient.Version.HTTP_1_1)
|
|
|
- .POST(HttpRequest.BodyPublishers.ofString(getFormDataAsString(formData)))
|
|
|
- .build();
|
|
|
- HttpResponse<String> httpResponse = httpClient.send(httpRequest, HttpResponse.BodyHandlers.ofString());
|
|
|
- int statusCode = httpResponse.statusCode();
|
|
|
- String body = httpResponse.body();
|
|
|
- if (statusCode != 200) {
|
|
|
- throw new Exception(body);
|
|
|
- }
|
|
|
-
|
|
|
- Type type = new TypeToken<WebResult<ConvertedImageInfo>>(){}.getType();
|
|
|
- WebResult<ConvertedImageInfo> webResult = JsonConverter.jsonToObject(body, type);
|
|
|
- if (webResult.getCode() != 0) {
|
|
|
- throw new Exception(webResult.getMsg());
|
|
|
- }
|
|
|
-
|
|
|
- return webResult.getData();
|
|
|
- }
|
|
|
-
|
|
|
- public AudioInfo getAudioInfo(int channelCode, String objectId) throws Exception {
|
|
|
- String api = String.format("%s/api/oss/sdk/object/audio/info/?channelCode=%s&objectId=%s", endpoint, channelCode, objectId);
|
|
|
- HttpRequest httpRequest = HttpRequest.newBuilder(new URI(api))
|
|
|
- .header("authorization", "Bearer " + token)
|
|
|
- .version(HttpClient.Version.HTTP_1_1)
|
|
|
- .GET()
|
|
|
- .build();
|
|
|
- HttpResponse<String> httpResponse = httpClient.send(httpRequest, HttpResponse.BodyHandlers.ofString());
|
|
|
- int statusCode = httpResponse.statusCode();
|
|
|
- String body = httpResponse.body();
|
|
|
- if (statusCode != 200) {
|
|
|
- throw new Exception(body);
|
|
|
- }
|
|
|
-
|
|
|
- Type type = new TypeToken<WebResult<AudioInfo>>(){}.getType();
|
|
|
- WebResult<AudioInfo> webResult = JsonConverter.jsonToObject(body, type);
|
|
|
- if (webResult.getCode() != 0) {
|
|
|
- throw new Exception(webResult.getMsg());
|
|
|
- }
|
|
|
-
|
|
|
- return webResult.getData();
|
|
|
- }
|
|
|
-
|
|
|
- // ****************************************************************************************************************
|
|
|
- // 音视频转码相关接口
|
|
|
- // ****************************************************************************************************************
|
|
|
- public void convertAudio(String audioFileId) throws Exception {
|
|
|
- String api = String.format("%s/api/oss/sdk/object/convert/audio/%s", endpoint, audioFileId);
|
|
|
- convert(api);
|
|
|
- }
|
|
|
-
|
|
|
- public void convertVideo(String videoFileId) throws Exception {
|
|
|
- String api = String.format("%s/api/oss/sdk/object/convert/video/%s", endpoint, videoFileId);
|
|
|
- convert(api);
|
|
|
- }
|
|
|
-
|
|
|
- private void convert(String api) throws Exception {
|
|
|
- MultiPartBodyPublisher publisher = new MultiPartBodyPublisher();
|
|
|
- HttpRequest httpRequest = HttpRequest.newBuilder(new URI(api))
|
|
|
- .header("authorization", "Bearer " + token)
|
|
|
- .version(HttpClient.Version.HTTP_1_1)
|
|
|
- .POST(publisher.build())
|
|
|
- .build();
|
|
|
- HttpResponse<String> httpResponse = httpClient.send(httpRequest, HttpResponse.BodyHandlers.ofString());
|
|
|
- int statusCode = httpResponse.statusCode();
|
|
|
- String body = httpResponse.body();
|
|
|
- if (statusCode != 200) {
|
|
|
- throw new Exception(body);
|
|
|
- }
|
|
|
-
|
|
|
- Type type = new TypeToken<WebResult<String>>(){}.getType();
|
|
|
- WebResult<String> webResult = JsonConverter.jsonToObject(body, type);
|
|
|
- if (webResult.getCode() != 0) {
|
|
|
- throw new Exception(webResult.getMsg());
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // ****************************************************************************************************************
|
|
|
- // 对象访问接口
|
|
|
- // ****************************************************************************************************************
|
|
|
- public UploadFileRet putObject(File file, int channelCode) throws Exception {
|
|
|
- ServerInfo serverInfo = getUploadStore(channelCode);
|
|
|
- if (serverInfo == null) {
|
|
|
- throw new Exception("获取 server_info 失败");
|
|
|
- }
|
|
|
- String ossUrl = serverInfo.getOssUrl();
|
|
|
- String token = serverInfo.getToken();
|
|
|
-
|
|
|
- OssStoreClient ossStoreClient = new OssStoreClient(ossUrl);
|
|
|
- UploadFileRet uploadFileRet = ossStoreClient.putObject(file, channelCode, token);
|
|
|
- return uploadFileRet;
|
|
|
- }
|
|
|
-
|
|
|
- public UploadFileRet postObject(File file, int channelCode) throws Exception {
|
|
|
- ServerInfo serverInfo = getUploadStore(channelCode);
|
|
|
- if (serverInfo == null) {
|
|
|
- throw new Exception("获取 server_info 失败");
|
|
|
- }
|
|
|
- String ossUrl = serverInfo.getOssUrl();
|
|
|
- String token = serverInfo.getToken();
|
|
|
-
|
|
|
- OssStoreClient ossStoreClient = new OssStoreClient(ossUrl);
|
|
|
- UploadFileRet uploadFileRet = ossStoreClient.postObjectWithJdkHttp(file, channelCode, token);
|
|
|
- return uploadFileRet;
|
|
|
- }
|
|
|
-
|
|
|
- public UploadFileRet postObjectByMultiparts(File file, int channelCode) throws Exception {
|
|
|
- ServerInfo serverInfo = getUploadStore(channelCode);
|
|
|
- if (serverInfo == null) {
|
|
|
- throw new Exception("获取 server_info 失败");
|
|
|
- }
|
|
|
- String ossUrl = serverInfo.getOssUrl();
|
|
|
- String token = serverInfo.getToken();
|
|
|
-
|
|
|
- ObjectMultipartUploadService multipartUploadService = new ObjectMultipartUploadService(ossUrl, token);
|
|
|
- UploadFileRet uploadFileRet = multipartUploadService.uploadFilePart(file, channelCode);
|
|
|
- return uploadFileRet;
|
|
|
- }
|
|
|
-
|
|
|
- public boolean headObject(String objectName) {
|
|
|
- return false;
|
|
|
- }
|
|
|
-
|
|
|
- public String getObject(String objectName, int channelCode, String savedDir) throws Exception {
|
|
|
- ServerInfo serverInfo = getUploadStore(channelCode);
|
|
|
- if (serverInfo == null) {
|
|
|
- throw new Exception("获取 server_info 失败");
|
|
|
- }
|
|
|
- String ossUrl = serverInfo.getOssUrl();
|
|
|
- String token = serverInfo.getToken();
|
|
|
-
|
|
|
- OssStoreClient ossStoreClient = new OssStoreClient(ossUrl);
|
|
|
- return ossStoreClient.getObject(objectName, savedDir);
|
|
|
- }
|
|
|
-}
|