接口描述:

  • 获取上传Token,同时会返回上传地址,各个具体的参数值,用于实际上传所用。

请求 URL:

  • http|https://host/api/v1/upload/method/get.upload.token/

请求方式:

  • GET
  • POST

是否授权:

  • 需要授权

业务参数:

参数名 类型 是否必须 范围值 默认值 示例值 描述
type string in:web,app web app 终端类型,详见「SDK或APP调用」

响应参数:

参数名 类型 是否返回 示例值 描述
status integer 200 状态码
message string success 消息信息
data object [] 返回对象
data 类型 是否返回 示例值 描述
token array [] Token对象,附带上传地址
expires integer 0 Token截止有效时间戳 0=无限制
token 类型 是否返回 示例值 描述
upload_url object [] 上传地址对象,详见「获取上传地址」
token string 上传令牌,aliyun模块稍有不同
N… string 其余参数,见备注
upload_url 类型 是否返回 示例值 描述
upload_url string 实际上传请求地址
module string careyshop 模块名
param array [] 上传时需要用到的参数

CareyShop(本地上传) 响应示例:

  1. {
  2. "status": 200,
  3. "message": "success",
  4. "data": {
  5. "token": {
  6. "upload_url": {
  7. "upload_url": "http://host/api/v1/upload/method/add.upload.list.html",
  8. "module": "careyshop",
  9. "param": [
  10. {
  11. "name": "x:replace",
  12. "type": "hidden",
  13. "default": ""
  14. },
  15. {
  16. "name": "x:parent_id",
  17. "type": "hidden",
  18. "default": 0
  19. },
  20. {
  21. "name": "x:filename",
  22. "type": "hidden",
  23. "default": ""
  24. },
  25. {
  26. "name": "token",
  27. "type": "hidden",
  28. "default": ""
  29. },
  30. {
  31. "name": "file",
  32. "type": "file",
  33. "default": ""
  34. }
  35. ]
  36. },
  37. "token": "careyshop"
  38. },
  39. "expires": 0
  40. }
  41. }

七牛云 KODO 响应示例:

  1. {
  2. "status": 200,
  3. "message": "success",
  4. "data": {
  5. "token": {
  6. "upload_url": {
  7. "upload_url": "http://upload-jjh.qiniup.com/",
  8. "module": "qiniu",
  9. "param": [
  10. {
  11. "name": "x:replace",
  12. "type": "hidden",
  13. "default": ""
  14. },
  15. {
  16. "name": "x:parent_id",
  17. "type": "hidden",
  18. "default": 0
  19. },
  20. {
  21. "name": "x:filename",
  22. "type": "hidden",
  23. "default": ""
  24. },
  25. {
  26. "name": "key",
  27. "type": "hidden",
  28. "default": ""
  29. },
  30. {
  31. "name": "token",
  32. "type": "hidden",
  33. "default": ""
  34. },
  35. {
  36. "name": "file",
  37. "type": "file",
  38. "default": ""
  39. }
  40. ]
  41. },
  42. "token": "-eibVM1dkuOQU9vbF9oMRbiMtw4t_-QUMQJgPPDJ:cLUJRYNYzrFsNvC1l7lv1UBNlJw=:eyJmc2l6ZUxpbWl0IjoyMDk3MTUyLCJpc1ByZWZpeGFsU2NvcGUiOjEsImNhbGxiYWNrVXJsIjoiaHR0cDpcL1wvY2FyZXlzaG9wLm9ydWVpLmNvbVwvYXBpXC92MVwvdXBsb2FkXC9tZXRob2RcL3B1dC51cGxvYWQuZGF0YVwvbW9kdWxlXC9xaW5pdS5odG1sIiwiY2FsbGJhY2tCb2R5IjoicmVwbGFjZT0kKHg6cmVwbGFjZSkmcGFyZW50X2lkPSQoeDpwYXJlbnRfaWQpJmZpbGVuYW1lPSQoeDpmaWxlbmFtZSkmbWltZT0kKG1pbWVUeXBlKSZwYXRoPSQoa2V5KSZzaXplPSQoZnNpemUpJm5hbWU9JChmbmFtZSkmd2lkdGg9JChpbWFnZUluZm8ud2lkdGgpJmhlaWdodD0kKGltYWdlSW5mby5oZWlnaHQpJmhhc2g9JChldGFnKSIsImNhbGxiYWNrQm9keVR5cGUiOiJhcHBsaWNhdGlvblwveC13d3ctZm9ybS11cmxlbmNvZGVkIiwic2NvcGUiOiJjYXJleXNob3A6dXBsb2Fkc1wvZmlsZXNcLzIwMTgwNTI4XC8iLCJkZWFkbGluZSI6MTUyNzQ0NDgxNX0=",
  43. "dir": "uploads/files/20180528/"
  44. },
  45. "expires": 1527444816
  46. }
  47. }

阿里云 OSS 响应示例:

  1. {
  2. "status": 200,
  3. "message": "success",
  4. "data": {
  5. "token": {
  6. "upload_url": {
  7. "upload_url": "http://careyshop.oss-cn-hangzhou.aliyuncs.com/",
  8. "module": "aliyun",
  9. "param": [
  10. {
  11. "name": "x:replace",
  12. "type": "hidden",
  13. "default": ""
  14. },
  15. {
  16. "name": "x:parent_id",
  17. "type": "hidden",
  18. "default": 0
  19. },
  20. {
  21. "name": "x:filename",
  22. "type": "hidden",
  23. "default": ""
  24. },
  25. {
  26. "name": "OSSAccessKeyId",
  27. "type": "hidden",
  28. "default": ""
  29. },
  30. {
  31. "name": "policy",
  32. "type": "hidden",
  33. "default": ""
  34. },
  35. {
  36. "name": "Signature",
  37. "type": "hidden",
  38. "default": ""
  39. },
  40. {
  41. "name": "callback",
  42. "type": "hidden",
  43. "default": ""
  44. },
  45. {
  46. "name": "key",
  47. "type": "hidden",
  48. "default": ""
  49. },
  50. {
  51. "name": "success_action_status",
  52. "type": "hidden",
  53. "default": 200
  54. },
  55. {
  56. "name": "file",
  57. "type": "file",
  58. "default": ""
  59. }
  60. ]
  61. },
  62. "OSSAccessKeyId": "LTAIiZASEnhdoDWO",
  63. "policy": "eyJleHBpcmF0aW9uIjoiMjAxOC0wNS0yOFQwMjowNzo1M1oiLCJjb25kaXRpb25zIjpbWyJjb250ZW50LWxlbmd0aC1yYW5nZSIsMCwyMDk3MTUyXSxbInN0YXJ0cy13aXRoIiwiJGtleSIsInVwbG9hZHNcL2ZpbGVzXC8yMDE4MDUyOFwvIl1dfQ==",
  64. "Signature": "do5qa+GW1veeOVejMjlB2qRG/Wg=",
  65. "callback": "eyJjYWxsYmFja1VybCI6Imh0dHA6XC9cL2NhcmV5c2hvcC5vcnVlaS5jb21cL2FwaVwvdjFcL3VwbG9hZFwvbWV0aG9kXC9wdXQudXBsb2FkLmRhdGFcL21vZHVsZVwvYWxpeXVuLmh0bWwiLCJjYWxsYmFja0JvZHkiOiJyZXBsYWNlPSR7eDpyZXBsYWNlfSZwYXJlbnRfaWQ9JHt4OnBhcmVudF9pZH0mZmlsZW5hbWU9JHt4OmZpbGVuYW1lfSZtaW1lPSR7bWltZVR5cGV9JnNpemU9JHtzaXplfSZ3aWR0aD0ke2ltYWdlSW5mby53aWR0aH0maGVpZ2h0PSR7aW1hZ2VJbmZvLmhlaWdodH0mcGF0aD0ke29iamVjdH0maGFzaD0ke2V0YWd9IiwiY2FsbGJhY2tCb2R5VHlwZSI6ImFwcGxpY2F0aW9uXC94LXd3dy1mb3JtLXVybGVuY29kZWQifQ==",
  66. "dir": "uploads/files/20180528/"
  67. },
  68. "expires": 1527444473
  69. }
  70. }

备注:

  1. 除了x:*自定义参数外,其余需要用到的请求参数都已经由系统给出,只要原样填写上去即可。

  2. 需要额外注意系统给出的参数dir和请求参数key,使用careyshop模块可以忽略。

    • 返回参数dir由框架系统给出,表示 OSS 资源上传目录路径,路径名不可修改。
    • 请求参数key是 OSS 所需要的资源标识,最终完整的标识应该是dir + 随机文件名 + 文件后缀
      • 假设返回参数dir值为uploads/files/20180528/
      • 那么完整key示例(文件名随机) uploads/files/20180528/dff3c7542c7ea.jpg
    • 请求参数key中的文件名建议随机产生,可以使用GUID,否则容易出现以下情况。
      1. OSS 返回报错。
      2. 原资源被新的资源所替换。
      3. 总之就是难以维护,爱随不随,不随别哭。
  3. expires有效期内Token(包括其他返回参数)可以重复使用。

  4. 返回系统设置中配置的默认上传模块

文档更新时间: 2018-06-20 11:25