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

參數(shù)
| 名稱 | 類型 | 必須 | 說明 |
|---|---|---|---|
| option | Object | 是 | |
| option.cloudPath | String | 是 | 云存儲(chǔ)文件存儲(chǔ)路徑 |
| option.fileContent | Buffer/ReadableStream | 是 | 文件內(nèi)容 |
| option.contentType | String | 是 | 文件 Conetent-Type |
| option.contentLength | String | 是 | 文件:Content-Length |
返回值 Promise
resolve 結(jié)果:
| 名稱 | 類型 | 說明 |
|---|---|---|
| requestID | String | 請(qǐng)求 ID |
| fileID | String | 文件 ID |
| statusCode | Number | 云存儲(chǔ)服務(wù)器返回狀態(tài)碼 |
reject 結(jié)果:
| 名稱 | 類型 | 說明 |
|---|---|---|
| code | String | 錯(cuò)誤碼 |
| message | String | 錯(cuò)誤信息 |
代碼示例
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
網(wǎng)頁網(wǎng)址:http://m.5511xx.com/article/djpcssc.html


咨詢
建站咨詢
