{"id":21518170,"url":"https://github.com/ucloud/ufile-sdk-java","last_synced_at":"2025-04-06T08:14:36.106Z","repository":{"id":33946286,"uuid":"162400575","full_name":"ucloud/ufile-sdk-java","owner":"ucloud","description":"UCloud 对象存储官方 SDK","archived":false,"fork":false,"pushed_at":"2025-02-14T05:01:23.000Z","size":19555,"stargazers_count":29,"open_issues_count":9,"forks_count":23,"subscribers_count":10,"default_branch":"master","last_synced_at":"2025-03-30T07:09:06.620Z","etag":null,"topics":["java","library","object-storage","ucloud-sdk"],"latest_commit_sha":null,"homepage":"https://www.ucloud.cn/","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ucloud.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-12-19T07:40:19.000Z","updated_at":"2025-02-14T05:01:27.000Z","dependencies_parsed_at":"2024-01-04T05:31:39.172Z","dependency_job_id":"a295dc40-4692-4aef-89cd-c9d0f6d31b7f","html_url":"https://github.com/ucloud/ufile-sdk-java","commit_stats":null,"previous_names":[],"tags_count":31,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ucloud%2Fufile-sdk-java","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ucloud%2Fufile-sdk-java/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ucloud%2Fufile-sdk-java/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ucloud%2Fufile-sdk-java/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ucloud","download_url":"https://codeload.github.com/ucloud/ufile-sdk-java/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247451667,"owners_count":20940944,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["java","library","object-storage","ucloud-sdk"],"created_at":"2024-11-24T00:50:24.563Z","updated_at":"2025-04-06T08:14:36.074Z","avatar_url":"https://github.com/ucloud.png","language":"Java","readme":"# UCloud US3 (原名UFile) SDK for Java\n\n[![](https://img.shields.io/github/release/ucloud/ufile-sdk-java.svg)](https://github.com/ucloud/ufile-sdk-java)\n[![](https://img.shields.io/github/last-commit/ucloud/ufile-sdk-java.svg)](https://github.com/ucloud/ufile-sdk-java)\n[![](https://img.shields.io/github/commits-since/ucloud/ufile-sdk-java/latest.svg)](https://github.com/ucloud/ufile-sdk-java)\n\n## Version History\n- ~~[Ver 1.0.0](https://github.com/ufilesdk-dev/ufile-javasdk)~~ 不建议使用\n\n## 环境要求\n- 开发环境: Java 1.7或以上\n- 运行环境: Java 1.7或以上\n\n## API Doc\n\n- **[ufile-client-java ](https://github.com/ucloud/ufile-sdk-java/tree/master/ufile/ufile-client-java/apidocs.zip)**\n    - **[ufile-core ](https://github.com/ucloud/ufile-sdk-java/tree/master/ufile/ufile-core/apidocs.zip)**\n    \n## 安装\n- Maven\n\n    您可以通过在pom.xml中添加以下依赖项，来配置您的Maven项目\n\n    ``` xml\n    \u003cdependency\u003e\n        \u003cgroupId\u003ecn.ucloud.ufile\u003c/groupId\u003e\n        \u003cartifactId\u003eufile-client-java\u003c/artifactId\u003e\n        \u003cversion\u003elatest-release-version\u003c/version\u003e\n    \u003c/dependency\u003e\n    ```\n\n- Gradle\n\n    ``` java\n    dependencies {\n        /*\n         * your other dependencies\n         */\n        implementation 'cn.ucloud.ufile:ufile-client-java:latest-release-version'\n    }\n    ```\n\n## 快速入门\n\n- 基本说明：\n    - 所有API均包含同步执行(execute)和异步执行(executeAsync)两种执行方式。\n    \n    - 同步执行会返回指定的业务结果类，若执行出错则会抛出UfileException为父类的异常；\n    \n    - 异步执行需要传入UfileCallback\u003cT\u003e的回调接口，执行成功时会回调onResponse，泛型\u003cT\u003e为回调结果(即：同步执行的返回类型)，**值得注意的是，若Ufile Server业务错误，也会回调onResponse，请注意结果类中的信息**，若出现异常，则回调onError。\n    \n    - 如果是上传下载等耗时API，建议使用异步执行(executeAsync)，并可以重写UfileCallback中的onProgress回调来进行进度监听\n\n## 配置UfileClient\n\n- 必须在使用UfileClient之前调用，即：必须是UfileClient第一个调用的方法才有效。否则使用默认UfileClient.Config\n\n    ``` java\n    UfileClient.configure(new UfileClient.Config(\n                    new HttpClient.Config(int maxIdleConnections, long keepAliveDuration, TimeUnit keepAliveTimeUnit)\n                            .setTimeout(连接超时ms，读取超时ms，写入超时ms)\n                            .setExecutorService(线程池)\n                            .addInterceptor(okhttp3拦截器)\n                            .addNetInterceptor(okhttp3网络拦截器)));\n    ```\n\n### Bucket相关操作\n``` java\n// Bucket相关API的授权器\nBucketAuthorization BUCKET_AUTHORIZER = new UfileBucketLocalAuthorization(\n            \"Your PublicKey\", \"Your PrivateKey\");\n            \nUfileClient.bucket(BUCKET_AUTHORIZER)\n    .APIs       // Bucket相关操作API\n    .execute() or executeAsync(UfileCallback\u003cT\u003e)\n```\n##### 创建Bucket\n\n- 同步\n\n    ``` java\n    try {\n        BucketResponse res = UfileClient.bucket(BUCKET_AUTHORIZER)\n            .createBucket(bucketName, region, bucketType)\n            .execute();\n    } catch (UfileClientException e) {\n        e.printStackTrace();\n    } catch (UfileServerException e) {\n        e.printStackTrace();\n    }\n    ```\n    \n- 异步\n\n    ``` java\n    UfileClient.bucket(BUCKET_AUTHORIZER)\n        .createBucket(bucketName, region, bucketType)\n        .executeAsync(new UfileCallback\u003cBucketResponse\u003e() {\n            @Override\n            public void onResponse(BucketResponse response) {\n                \n            }\n        \n            @Override\n            public void onError(Request request, ApiError error, UfileErrorBean response) {\n                \n            }\n    });\n    ```\n\n### 对象相关操作\n\n##### 关于ObjectConfig的region参数，是指您的bucket所创建在的地区编码，请参考[UCloud 地区列表](https://docs.ucloud.cn/api/summary/regionlist.html)\n\n``` java\n// 对象相关API的授权器\nObjectAuthorization OBJECT_AUTHORIZER = new UfileObjectLocalAuthorization(\n            \"Your PublicKey\", \"Your PrivateKey\");\n            \n/**\n * 您也可以创建远程对象相关API的授权器，远程授权器将签名私钥放于签名服务器上，更为安全\n * 远程签名服务端示例代码在 (https://github.com/ucloud/ufile-sdk-auth-server)\n * 您也可以自行继承ObjectRemoteAuthorization来重写远程签名逻辑\n */\nObjectAuthorization OBJECT_AUTHORIZER = new UfileObjectRemoteAuthorization(\n            您的公钥,\n            new ObjectRemoteAuthorization.ApiConfig(\n                    \"http://your_domain/applyAuth\",\n                    \"http://your_domain/applyPrivateUrlAuth\"\n            ));\n// 对象操作需要ObjectConfig来配置您的地区和域名后缀\nObjectConfig config = new ObjectConfig(\"your bucket region\", \"ufileos.com\");\n\n/** \n * 您也可以使用已登记的自定义域名\n * 注意'http://www.your_domain.com'指向的是某个特定的bucket+region+域名后缀，\n * eg：http://www.your_domain.com -\u003e www.your_bucket.bucket_region.ufileos.com\n */\nObjectConfig config = new ObjectConfig(\"http://www.your_domain.com\");\n\n/**\n * ObjectConfig同时支持从本地文件来导入\n * 配置文件内容必须是含有以下参数的json字符串：\n *     {\"Region\":\"\",\"ProxySuffix\":\"\"} \n *     或\n *     {\"CustomDomain\":\"\"}\n */\n try {\n     ObjectConfig.loadProfile(new File(\"your config profile path\"));\n } catch (UfileFileException e) {\n     e.printStackTrace();\n }\n\nUfileClient.object(OBJECT_AUTHORIZER, config)\n    .APIs           // 对象存储相关API\n    .execute() or executeAsync(UfileCallback\u003cT\u003e)\n```\n\n##### 上传文件\n\n- 同步\n\n    ``` java\n    File file = new File(\"your file path\");\n    \n    try {\n        PutObjectResultBean response = UfileClient.object(Constants.OBJECT_AUTHORIZER, config)\n             .putObject(file, \"mimeType\")\n             .nameAs(\"save as keyName\")\n             .toBucket(\"upload to which bucket\")\n             /**\n              * 是否上传校验MD5, Default = true\n              */\n         //  .withVerifyMd5(false)\n             /**\n              * 指定progress callback的间隔, Default = 每秒回调\n              */\n         //  .withProgressConfig(ProgressConfig.callbackWithPercent(10))\n             /**\n              * 配置进度监听\n              */\n             .setOnProgressListener(new OnProgressListener() {\n                  @Override\n                  public void onProgress(long bytesWritten, long contentLength) {\n                      \n                  }\n             })\n             .execute();\n    } catch (UfileClientException e) {\n        e.printStackTrace();\n    } catch (UfileServerException e) {\n        e.printStackTrace();\n    }\n    ```\n\n- 异步\n\n    ``` java\n    File file = new File(\"your file path\");\n    \n    UfileClient.object(OBJECT_AUTHORIZER, config)\n         .putObject(file, \"mimeType\")\n         .nameAs(\"save as keyName\")\n         .toBucket(\"upload to which bucket\")\n         /**\n          * 是否上传校验MD5, Default = true\n          */\n    //   .withVerifyMd5(false)\n         /**\n          *指定progress callback的间隔, Default = 每秒回调\n          */\n    //   .withProgressConfig(ProgressConfig.callbackWithPercent(10))\n         .executeAsync(new UfileCallback\u003cPutObjectResultBean\u003e() {\n             @Override\n                public void onProgress(long bytesWritten, long contentLength) {\n                    \n                }\n    \n                @Override\n                public void onResponse(PutObjectResultBean response) {\n                    \n                }\n    \n                @Override\n                public void onError(Request request, ApiError error, UfileErrorBean response) {\n                    \n                }\n         });\n    ```\n\n\n## License\n[Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0.html)\n\n## 作者\n- [Joshua Yin](https://github.com/joshuayin)\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fucloud%2Fufile-sdk-java","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fucloud%2Fufile-sdk-java","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fucloud%2Fufile-sdk-java/lists"}