Welcome to my website, have a nice day!
Dream it, Do it, Make it!

Seafile Java API接口实现示例

JAVA代码

使用JAVA实现Seafile创建资料库、上传文件、创建文件夹等的接口代码如下:

    /**
     * 测试服务状态
     *
     * @param client
     * @return
     */
    public String ping(OkHttpClient client) {
        Request request = new Request.Builder()
                .get()
                .url(SERVICE_URL + "/api2/ping/")
                .build();
        try (Response response = client.newCall(request).execute()) {
            if (response.isSuccessful()) {
                return response.body().string();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }


    /**
     * 获取token
     *
     * @param client
     * @param username 账号
     * @param password 密码
     * @return
     */
    public String obtainAuthToken(OkHttpClient client, String username, String password) {
        RequestBody body = new FormBody.Builder()
                .add("username", username)
                .add("password", password)
                .build();
        Request request = new Request.Builder()
                .url(SERVICE_URL + "/api2/auth-token/")
                .header("Content-Type", "application/x-www-form-urlencoded")
                .post(body)
                .build();
        try (Response response = client.newCall(request).execute()) {
            JSONObject jObj = parseJson(response.body().string());
            return jObj.getString("token");
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }

更多接口实现的具体代码详见:Seafile_WebApi

此系列的其他文章

  1. Centos 7基于seafile搭建个人网盘服务端(mysql环境)
  2. Centos 7基于seafile离线搭建个人网盘服务端(mariadb环境)
  3. Seafile Java API接口实现示例
  4. CentOS 7搭建seafile服务端(远程连接mysql数据库)

参考:

  1. 官方示例
  2. Seafile_WebAPI
  3. Web API (For Seafile server v5.1.0+)
赞(0)
未经允许禁止转载:Ddmit » Seafile Java API接口实现示例

评论 抢沙发

登录

找回密码

注册