文件模块 - 文件操作

优质
小牛编辑
131浏览
2023-12-01

获取文件详情

接口

GET https://cloud.minapp.com/oserve/v1/file/:file_id/

其中 :file_id 需替换为你的文件 ID

代码示例

{% tabs getFileDetailCurl=”Curl”, getFileDetailNode=”Node”, getFileDetailPHP=”PHP” %}

{% content “getFileDetailCurl” %}

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

{% content “getFileDetailNode” %}

  1. var request = require('request');
  2. var opt = {
  3. uri: 'https://cloud.minapp.com/oserve/v1/file/5a2fe93308443e313a428cxx/', // 5a6ad3cffff1d675b9e2cexx 对应 uri :file_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 “getFileDetailPHP” %}

  1. <?php
  2. $file_id = '5a2fe93308443e313a428cxx'; // 文件 ID
  3. $url = "https://cloud.minapp.com/oserve/v1/file/{$file_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. "categories": [
  3. {
  4. "id": "5a1ba7b708443e7fc5f2fb18",
  5. "name": "Category",
  6. }
  7. ],
  8. "cdn_path": "1eJCS1MFGdvaaBoV.png",
  9. "created_at": 1511762369,
  10. "id": "5a1ba9c1fff1d651135e5ff1",
  11. "media_type": "image",
  12. "mime_type": "image/png",
  13. "name": "box_close.png",
  14. "path": "https://cloud-minapp-287.cloud.ifanrusercontent.com/1eJCS1MFGdvaaBoV.png",
  15. "size": 3652,
  16. "status": "success"
  17. }

获取文件列表

接口

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

参数说明

Content-Type: application/json

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

代码示例

{% tabs getFileListCurl=”Curl”, getFileListNode=”Node”, getFileListPHP=”PHP” %}

{% content “getFileListCurl” %}

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

{% content “getFileListNode” %}

  1. var request = require('request');
  2. var opt = {
  3. uri: 'https://cloud.minapp.com/oserve/v1/file/',
  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 “getFileListPHP” %}

  1. <?php
  2. $url = "https://cloud.minapp.com/oserve/v1/file/";
  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 %}

删除文件

接口

DELETE https://cloud.minapp.com/oserve/v1/file/:file_id/

其中 :file_id 需替换为你的文件 ID

代码示例

{% tabs deleteFileCurl=”Curl”, deleteFileNode=”Node”, deleteFilePHP=”PHP” %}

{% content “deleteFileCurl” %}

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

{% content “deleteFileNode” %}

  1. var request = require('request');
  2. var opt = {
  3. uri: 'https://cloud.minapp.com/oserve/v1/file/5a45f22bfff1d659681c87xx/', // 5a6ad3cffff1d675b9e2cexx 对应 uri :file_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 “deleteFilePHP” %}

  1. <?php
  2. $file_id = '5a45f22bfff1d659681c87xx'; // 文件 ID
  3. $url = "https://cloud.minapp.com/oserve/v1/file/{$file_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 删除成功

批量删除文件

接口

DELETE https://cloud.minapp.com/oserve/v1/file/?id__in=:file1_id,:file2_id

代码示例

{% tabs patchDeleteCurl=”Curl”, patchDeleteNode=”Node”, patchDeletePHP=”PHP” %}

{% content “patchDeleteCurl” %}

  1. curl -X DELETE \
  2. -H "Authorization: Bearer 58f6cd9f84b1b0c04941fbd4d87bc5f14a785107" \
  3. -H "Content-Type: application/json" \
  4. https://cloud.minapp.com/oserve/v1/file/?id__in=5a1ba9c1fff1d651135e5ff1,59ca3d275f281f58523fc47a

{% content “patchDeleteNode” %}

  1. var request = require('request');
  2. var opt = {
  3. uri: 'https://cloud.minapp.com/oserve/v1/file/?id__in=5a3b8e8908443e06aa6f0a99,5a3b673308443e643f1b0c47',
  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 “patchDeletePHP” %}

  1. <?php
  2. $file_id[] = '5a45f22bfff1d659681cxxxx'; // 文件 ID
  3. $file_id[] = '5a3b673308443e643f1bxxxx'; // 文件 ID
  4. $url = "https://cloud.minapp.com/oserve/v1/file/?id__in=".implode(',',$file_id);
  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, 'DELETE');
  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 %}

状态码说明

204 删除成功