微信小程序开发-阿里云服务器OSS上传(分享篇CV战士)
注意:仅供个人学习使用!!!
注意:仅供个人学习使用!!!
注意:仅供个人学习使用!!!
一、大致流程
请参考优快云博主 summer‘s forest 的文章:微信小程序直接上传文件到阿里云OSS
请参考51CTO博客博主 mob649e8153b214 的文章:微信小程序使用alioss上传
请参考脚本之家博主 Ho0229 的文章:微信小程序上传文件到阿里OSS教程
请参考博客园博主 程序员哆啦A梦 的文章:微信小程序环境下将文件上传到 OSS
二、阿里云服务器相关配置(必看!)
请参考开发者v1博主 ICEMAN 的文章:阿里服务器相关配置
三、微信小程序直传实践(必看!)
请参考 阿里云官方文档 :微信小程序直传实践Express
请参考 阿里云官方文档 :微信小程序直传实践PHP
四、其他参考
base64.js、crypto.js、alioss.js请参考简书博主 墨衣 的文章:微信小程序上传文件 阿里oss篇
base64.js
var Base64 = {
// private property
_keyStr: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",
// public method for encoding
encode: function(input) {
var output = "";
var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
var i = 0;
input = Base64._utf8_encode(input);
while (i < input.length) {
chr1 = input.charCodeAt(i++);
chr2 = input.charCodeAt(i++);
chr3 = input.charCodeAt(i++);
enc1 = chr1 >> 2;
enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
enc4 = chr3 & 63;
if (isNaN(chr2)) {
enc3 = enc4 = 64;
} else if (isNaN(chr3)) {
enc4 = 64;
}
output = output +
this._keyStr.charAt(enc1) + this._keyStr.charAt(enc2) +
this._keyStr.charAt(enc3) + this._keyStr.charAt(enc4);
}
return output;
},
// public method for decoding
decode: function(input) {
var output = "";
var chr1, chr2, chr3;
var enc1, enc2, enc3, enc4;
var i = 0;
input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
while (i < input.length) {
enc1 = this._keyStr.indexOf(input.charAt(i++));
enc2 = this._keyStr.indexOf(input.charAt(i++));
enc3 = this._keyStr.indexOf(input.charAt(i++));
enc4 = this._keyStr.indexOf(input.charAt(i++));
chr1 = (enc1 << 2) | (enc2 >> 4);
chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
chr3 = ((enc3 & 3) << 6) | enc4;
output = output + String.fromCharCode(chr1);
if (enc3 != 64) {
output = output + String.fromCharCode(chr2);