上传文件到云存储空间

参数
| 名称 | 类型 | 必须 | 说明 |
|---|---|---|---|
| option | Object | 是 | |
| option.cloudPath | String | 是 | 云存储文件存储路径 |
| option.fileContent | Buffer/ReadableStream | 是 | 文件内容 |
| option.contentType | String | 是 | 文件 Conetent-Type |
| option.contentLength | String | 是 | 文件:Content-Length |
返回值 Promise
resolve 结果:
| 名称 | 类型 | 说明 |
|---|---|---|
| requestID | String | 请求 ID |
| fileID | String | 文件 ID |
| statusCode | Number | 云存储服务器返回状态码 |
reject 结果:
| 名称 | 类型 | 说明 |
|---|---|---|
| code | String | 错误码 |
| message | String | 错误信息 |
代码示例
const cloud = require('swan-server-sdk')const path = require('path')const fs = require('fs')const util = require('util')exports.main = async (event, context) => {cloud.init(context)const filePath = path.join(__dirname, 'demo.jpg');const fileStream = fs.createReadStream(filePath);const fileStats = await util.promisify(fs.stat)(filePath)const res = await cloud.storage().uploadFile({cloudPath: 'photo/demo.jpg',fileContent: fileStream,contentType: 'image/jpeg',contentLength: fileStats.size})return res.fileID}
文章题目:创新互联百度小程序教程:cloud.uploadFile
转载来于:http://www.csdahua.cn/qtweb/news8/470458.html
网站建设、网络推广公司-快上网,是专注品牌与效果的网站制作,网络营销seo公司;服务项目有等
声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 快上网