新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
創(chuàng)新互聯(lián)百度小程序教程:cloud.uploadFile
- cloud.uploadFile
cloud.uploadFile
上傳文件到云存儲空間

參數(shù)
| 名稱 | 類型 | 必須 | 說明 |
|---|---|---|---|
| option | Object | 是 | |
| option.cloudPath | String | 是 | 云存儲文件存儲路徑 |
| option.fileContent | Buffer/ReadableStream | 是 | 文件內(nèi)容 |
| option.contentType | String | 是 | 文件 Conetent-Type |
| option.contentLength | String | 是 | 文件:Content-Length |
返回值 Promise
resolve 結(jié)果:
| 名稱 | 類型 | 說明 |
|---|---|---|
| requestID | String | 請求 ID |
| fileID | String | 文件 ID |
| statusCode | Number | 云存儲服務(wù)器返回狀態(tài)碼 |
reject 結(jié)果:
| 名稱 | 類型 | 說明 |
|---|---|---|
| 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}
網(wǎng)站題目:創(chuàng)新互聯(lián)百度小程序教程:cloud.uploadFile
URL標(biāo)題:http://fisionsoft.com.cn/article/djpcssc.html


咨詢
建站咨詢
