codecamp

QQ小程序 uploadFile

将本地资源上传至云存储空间,如果上传至同一路径则是覆盖。

请求参数

字段 说明 数据类型 默认值 必填
cloudPath 云存储路径,命名限制见文件名命名限制 String Y
fileContent 要上传文件的内容 Buffer 或 fs.ReadStream Y

Promise返回结果说明

字段 说明 数据类型
fileID 文件 ID String
statusCode 服务器返回的 HTTP 状态码 Number

错误返回参数

字段 说明 数据类型
errCode 错误码 Number
errMsg 错误信息,格式 apiName:fail msg String

使用示例

const cloud = require('qq-server-sdk')
const fs = require('fs')
const path = require('path')


cloud.init({
  env: cloud.DYNAMIC_CURRENT_ENV
})


exports.main = async (event, context) => {
  const fileStream = fs.createReadStream(path.join(__dirname, 'demo.jpg'))
  return await cloud.uploadFile({
    cloudPath: 'demo.jpg',
    fileContent: fileStream,
  })
}
QQ小程序 callFunction
QQ小程序 downloadFile
温馨提示
下载编程狮App,免费阅读超1000+编程语言教程
取消
确定
目录

QQ小程序 开发

硬件能力

QQ小程序 云开发

关闭

MIP.setData({ 'pageTheme' : getCookie('pageTheme') || {'day':true, 'night':false}, 'pageFontSize' : getCookie('pageFontSize') || 20 }); MIP.watch('pageTheme', function(newValue){ setCookie('pageTheme', JSON.stringify(newValue)) }); MIP.watch('pageFontSize', function(newValue){ setCookie('pageFontSize', newValue) }); function setCookie(name, value){ var days = 1; var exp = new Date(); exp.setTime(exp.getTime() + days*24*60*60*1000); document.cookie = name + '=' + value + ';expires=' + exp.toUTCString(); } function getCookie(name){ var reg = new RegExp('(^| )' + name + '=([^;]*)(;|$)'); return document.cookie.match(reg) ? JSON.parse(document.cookie.match(reg)[2]) : null; }