微信小程序上传阿里云OSS PostObject错误及排查

  1. 小程序端

upload.wxml

<view bindtap=’onChooseImage’>上传头像</view>

upload.js

Page({

onChooseImage: function () {

var that = this;

wx.chooseImage({

success(res) {

const tempFilePaths = res.tempFilePaths

that.getCloudCdnParams(tempFilePaths[0])

}

})

},

//获取签名oss鉴权信息

getCloudCdnParams: function (filePath) {

var that = this;

var dataUrl = ‘服务端获取签名接口’;

var params = new Object();

wx.request({

url: dataUrl,

method: “post”,

header: {

‘content-type’: ‘application/x-www-form-urlencoded’

},

success: function (res) {

that.uploadFileFun(res.data, filePath)

}

})

},

// 上传图片

uploadFileFun: function (result, filePath) {

//console.log(result)

var that = this;

var aliyunFileKey = result.dir + new Date().getTime() + Math.floor(Math.random() * 150) + ‘.png’;

console.log(aliyunFileKey)

wx.uploadFile({

url: result.host,

filePath: filePath,

name: ‘file’,

/**上传的参数**/

formData: {

name: filePath,

key: aliyunFileKey,

policy: result.policy,

OSSAccessKeyId: result.accessid,

success_action_status: “200”,

signature: result.signature,

},

success: function (res) {

/**这边上传成功后要自己拼接文件的地址**/

console.log(result.cdnurl + aliyunFileKey)

},

fail: function (res) {

console.log(res)

}

})

},

})

OSS PostObject错误及排查

https://yq.aliyun.com/articles/58524

 

发表评论

电子邮件地址不会被公开。 必填项已用*标注