• 文件分类操作
    • 创建文件分类
    • 获取分类详情
    • 获取文件分类列表
    • 修改文件分类
    • 删除文件分类

    文件分类操作

    创建文件分类

    接口

    POST https://cloud.minapp.com/oserve/v1/file-category/

    参数说明

    Content-Type: application/json

    参数 类型 必填 说明
    name String Y 文件分类的名称

    代码示例

    {% tabs createCategoryCurl=”Curl”, createCategoryNode=”Node”, createCategoryPHP=”PHP” %}

    {% content “createCategoryCurl” %}

    1. curl -X POST \
    2. -H "Authorization: Bearer 58f6cd9f84b1b0c04941fbd4d87bc5f14a785107" \
    3. -H "Content-Type: application/json" \
    4. -d '{"name": "Category"}' \
    5. https://cloud.minapp.com/oserve/v1/file-category/

    {% content “createCategoryNode” %}

    1. var request = require('request');
    2. var opt = {
    3. uri: 'https://cloud.minapp.com/oserve/v1/file-category/',
    4. method: 'POST',
    5. headers: {
    6. Authorization: `Bearer ${token}`
    7. },
    8. json: { // 指定 data 以 "Content-Type": 'application/json' 传送
    9. name: 'testCreateFile'
    10. }
    11. }
    12. request(opt, function(err, res, body) {
    13. console.log(res.statusCode)
    14. })

    {% content “createCategoryPHP” %}

    1. <?php
    2. $param = ['name' =>'nickname'];
    3. $url = 'https://cloud.minapp.com/oserve/v1/file-category/';
    4. $ch = curl_init();
    5. $header = array(
    6. "Authorization: Bearer {$token}",
    7. 'Content-Type: application/json; charset=utf-8'
    8. );
    9. curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
    10. curl_setopt($ch, CURLOPT_TIMEOUT, 30);
    11. curl_setopt($ch, CURLOPT_URL, $url);
    12. curl_setopt($ch, CURLOPT_POST, true);
    13. curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($param));
    14. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    15. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
    16. $res['response'] = curl_exec($ch); // 反馈结果
    17. $res['status_code'] = curl_getinfo($ch, CURLINFO_HTTP_CODE); // 请求状态码
    18. curl_close($ch);

    {% endtabs %}

    状态码说明

    201 写入成功

    获取分类详情

    接口

    GET https://cloud.minapp.com/oserve/v1/file-category/:category_id/

    其中 :category_id 需替换为你的文件分类 ID

    代码示例

    {% tabs getDetailCurl=”Curl”, getDetailNode=”Node”, getDetailPHP=”PHP” %}

    {% content “getDetailCurl” %}

    1. curl -X GET \
    2. -H "Authorization: Bearer 58f6cd9f84b1b0c04941fbd4d87bc5f14a785107" \
    3. -H "Content-Type: application/json" \
    4. https://cloud.minapp.com/oserve/v1/file-category/5a1bb2ed7026d950ca7d2a78/

    {% content “getDetailNode”%}

    1. var request = require('request');
    2. var opt = {
    3. uri: 'https://cloud.minapp.com/oserve/v1/file-category/5a2fe91508443e3123dbe1xx/', // 5a2fe91508443e3123dbe1xx 对应 uri :category_id
    4. method: 'GET',
    5. headers: {
    6. Authorization: `Bearer ${token}`
    7. }
    8. }
    9. request(opt, function(err, res, body) {
    10. console.log(body)
    11. })

    {% content “getDetailPHP”%}

    1. <?php
    2. $category_id = '5a2fe91508443e3123dbe1xx'; // 文件分类 ID
    3. $url = "https://cloud.minapp.com/oserve/v1/file-category/{$category_id}/";
    4. $ch = curl_init();
    5. $header = array(
    6. "Authorization: Bearer {$token}",
    7. 'Content-Type: application/json; charset=utf-8'
    8. );
    9. curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
    10. curl_setopt($ch, CURLOPT_TIMEOUT, 30);
    11. curl_setopt($ch, CURLOPT_URL, $url);
    12. curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
    13. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    14. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
    15. $res = curl_exec($ch);
    16. curl_close($ch);

    {% endtabs %}

    返回示例

    1. {
    2. "files": 0,
    3. "id": "5a1bb2ed7026d950ca7d2a78",
    4. "name": "Category 1",
    5. "created_at": 1511761847,
    6. "parent": null,
    7. "subcategories": []
    8. }

    获取文件分类列表

    接口

    GET https://cloud.minapp.com/oserve/v1/file-category/

    参数说明

    Content-Type: application/json

    参数 类型 必填 说明
    order_by String N 排序(支持 created_at 进行排序)
    limit Number N 限制返回资源的个数,默认为 20 条,最大可设置为 1000
    offset Number N 设置返回资源的起始偏移值,默认为 0

    代码示例

    {% tabs getCategoryCurl=”Curl”, getCategoryNode=”Node”, getCategoryPHP=”PHP” %}

    {% content “getCategoryCurl” %}

    1. curl -X GET \
    2. -H "Authorization: Bearer 58f6cd9f84b1b0c04941fbd4d87bc5f14a785107" \
    3. -H "Content-Type: application/json" \
    4. -G \
    5. -d order_by=-created_at \
    6. https://cloud.minapp.com/oserve/v1/file-category/

    {% content “getCategoryNode” %}

    1. var request = require('request');
    2. var opt = {
    3. uri: 'https://cloud.minapp.com/oserve/v1/file-category/',
    4. method: 'GET',
    5. headers: {
    6. Authorization: `Bearer ${token}`
    7. },
    8. qs: { // query string, 被附加到uri的参数
    9. offset: 0, // 可选
    10. limit: 20, // 可选
    11. order_by: 'created_at' // 按照创建时间来排序,可选
    12. }
    13. }
    14. request(opt, function(err, res, body) {
    15. console.log(body)
    16. })

    {% content “getCategoryPHP”%}

    1. <?php
    2. $url = "https://cloud.minapp.com/oserve/v1/file-category/";
    3. $ch = curl_init();
    4. $header = array(
    5. "Authorization: Bearer {$token}",
    6. 'Content-Type: application/json; charset=utf-8'
    7. );
    8. curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
    9. curl_setopt($ch, CURLOPT_TIMEOUT, 30);
    10. curl_setopt($ch, CURLOPT_URL, $url);
    11. curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
    12. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    13. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
    14. $res = curl_exec($ch);
    15. curl_close($ch);

    {% endtabs %}

    返回示例

    1. {
    2. "meta": {
    3. "files": 7,
    4. "limit": 20,
    5. "next": null,
    6. "offset": 0,
    7. "previous": null,
    8. "total_count": 1
    9. },
    10. "objects": [
    11. {
    12. "files": 0,
    13. "id": "5a1bb2ed7026d950ca7d2a78",
    14. "name": "Category 1",
    15. "created_at": 1511761847
    16. }
    17. ]
    18. }

    字段 files 在返回中有两个地方出现;在 meta 中表示应用上传文件的数量总和;在 objects 中表示每个分类下的上传文件的数量。

    修改文件分类

    接口

    PUT https://cloud.minapp.com/oserve/v1/file-category/:category_id/

    其中 :category_id 需替换为你的文件分类 ID

    代码示例

    {% tabs modifyCategoryCurl=”Curl”, modifyCategoryNode=”Node”, modifyCategoryPHP=”PHP” %}

    {% content “modifyCategoryCurl” %}

    1. curl -X PUT \
    2. -H "Authorization: Bearer 58f6cd9f84b1b0c04941fbd4d87bc5f14a785107" \
    3. -H "Content-Type: application/json" \
    4. -d '{"name": "category"}' \
    5. https://cloud.minapp.com/oserve/v1/file-category/5a1bb2ed7026d950ca7d2a78/

    {% content “modifyCategoryNode” %}

    1. var request = require('request');
    2. var opt = {
    3. uri: 'https://cloud.minapp.com/oserve/v1/file-category/5a6ad3cffff1d675b9e2cexx/', // 5a6ad3cffff1d675b9e2cexx 对应 uri :category_id
    4. method: 'PUT',
    5. headers: {
    6. Authorization: `Bearer ${token}`
    7. },
    8. json: { // 指定 data 以 "Content-Type": 'application/json' 传送
    9. name: 'testCreateFiles'
    10. }
    11. }
    12. request(opt, function(err, res, body) {
    13. console.log(res.statusCode)
    14. })

    {% content “modifyCategoryPHP” %}

    1. <?php
    2. $category_id = '5a2fe91508443e3123dbe1xx'; // 文件分类 ID
    3. $url = "https://cloud.minapp.com/oserve/v1/file-category/{$category_id}/";
    4. $param['name'] = 'testCreateFiles';
    5. $ch = curl_init();
    6. $header = array(
    7. "Authorization: Bearer {$token}",
    8. 'Content-Type: application/json; charset=utf-8'
    9. );
    10. curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
    11. curl_setopt($ch, CURLOPT_TIMEOUT, 30);
    12. curl_setopt($ch, CURLOPT_URL, $url);
    13. curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
    14. curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($param));
    15. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    16. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
    17. $res['response'] = curl_exec($ch); // 反馈结果
    18. $res['status_code'] = curl_getinfo($ch, CURLINFO_HTTP_CODE); // 请求状态码
    19. curl_close($ch);

    {% endtabs %}

    返回示例

    1. {
    2. "files": 0,
    3. "id": "5a1bb2ed7026d950ca7d2a78",
    4. "name": "category",
    5. "created_at": 1511761847
    6. }

    状态码说明

    200 修改成功

    删除文件分类

    接口

    DELETE https://cloud.minapp.com/oserve/v1/file-category/:category_id/

    其中 :category_id 需替换为你的文件分类 ID

    代码示例

    {% tabs deleteCategoryCurl=”Curl”, deleteCategoryNode=”Node”, deleteCategoryPHP=”PHP” %}

    {% content “deleteCategoryCurl” %}

    1. curl -X DELETE \
    2. -H "Authorization: Bearer 58f6cd9f84b1b0c04941fbd4d87bc5f14a785107" \
    3. -H "Content-Type: application/json" \
    4. https://cloud.minapp.com/oserve/v1/file-category/5a1bb2ed7026d950ca7d2a78/

    {% content “deleteCategoryNode” %}

    1. var request = require('request');
    2. var opt = {
    3. uri: 'https://cloud.minapp.com/oserve/v1/file-category/5a6ad3cffff1d675b9e2cexx/', // 5a6ad3cffff1d675b9e2cexx 对应 uri :category_id
    4. method: 'DELETE',
    5. headers: {
    6. Authorization: `Bearer ${token}`
    7. }
    8. }
    9. request(opt, function(err, res, body) {
    10. console.log(res.statusCode)
    11. })

    {% content “deleteCategoryPHP” %}

    1. <?php
    2. $category_id = '5a2fe91508443e3123dbe1xx'; // 文件分类 ID
    3. $url = "https://cloud.minapp.com/oserve/v1/file-category/{$category_id}/";
    4. $ch = curl_init();
    5. $header = array(
    6. "Authorization: Bearer {$token}",
    7. 'Content-Type: application/json; charset=utf-8'
    8. );
    9. curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
    10. curl_setopt($ch, CURLOPT_TIMEOUT, 30);
    11. curl_setopt($ch, CURLOPT_URL, $url);
    12. curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE');
    13. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    14. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
    15. $res['response'] = curl_exec($ch); // 反馈结果
    16. $res['status_code'] = curl_getinfo($ch, CURLINFO_HTTP_CODE); // 请求状态码
    17. curl_close($ch);

    {% endtabs %}

    状态码说明

    204 删除成功