图片上传模块后端代码
oss_config.js配置文件代码(参照阿里云官方实例)
let oss =require('ali-oss')
let client = new oss({
region: '填写地区',
accessKeyId: '填写密钥id',
accessKeySecret: '填写密钥值',
bucket: ''
});
let fileOperation= {
//上传
//objectUrl文件路径,file文件
"putFile": async function (objectUrl,file) {
console.log(objectUrl,"上传",file);
try {
let result = await client.put(objectUrl, file);
// console.log(result.url)
return result.url;
} catch (err) {
console.log(err,"上传err");
}
return '';
},
}
module.exports = {
fileOperation
}
oss文件上传接口代码
此处先引用几个模块(oss配置模块、图片解析模块)
var fo = require('../module/oss_config')
var multiparty = require('multiparty');
va