-
Notifications
You must be signed in to change notification settings - Fork 578
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
我采用浏览器直接上传到oss, oss回调应用服务器有没有node.je 版本的。 #85
Comments
上面的代码能否转成js 版本。 |
@mrlong 我会在后续的版本中增加对oss callback的支持。 |
现在浏览器往 OSS 发请求的时候怎么设置 callback url ? @rockuw |
@wendycan 现在只能根据文档:https://help.aliyun.com/document_detail/oss/api-reference/object/Callback.html ,手动构造好 client.multipartUpload(storeAs, file, {
headers: {
'x-oss-callback': callback
}
}).then(function (result) {
console.log(result);
}).catch(function (err) {
console.log(err);
}); |
@rockuw 可以通过 url 带参数吗,还有就是我本来用 aliyun-sdk-js 的,但是没有找到设置 headers 的文档。aliyun-sdk-js 在哪里可以设置 headers ? |
带什么参数? |
|
@rockuw 非常感谢了 |
callback出了java、python、php等等的demo,有没有node版本的 |
我也在找node版本的~怎么就没有呢 |
aliyun-oss 的确是对nodejs 不够友好,找了好久终于找到解决方案了分享给大家 const crypto = require('crypto');
// 1.获取OSS的签名
// 例子 "Lw8CsG8j3iNCzQliYUxmCKuOiJzsPsPf86xkEqQmSNcZB6mccM0m5KqH5yXOPvreP6w37IHxzMqdjN4nLy0URw=="
const signatureBase64 = ctx.request.header.authorization;
// 2.获取公钥
// 例子 "-----BEGIN PUBLIC KEY-----\nMFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAKs/JBGzwUB2aVht4crBx3oIPBLNsjGs\nC0fTXv+nvlmklvkcolvpvXLTjaxUHR3W9LXxQ2EHXAJfCB+6H2YF1k8CAwEAAQ==\n-----END PUBLIC KEY-----\n"
const pubKeyUrl = Buffer.from(ctx.request.header['x-oss-pub-key-url'], 'base64').toString();
const pubKeyRes = await axios.get(pubKeyUrl);
const pubKey = pubKeyRes.data;
// 3 获取待签名字符串
// 例子 '/oss/callback\n{"tradeNo":"202007151283383770610798592","mime":"image/png","size":848409,"objectName":"local/upload/image/f2fb68c0c69911ea9b8367206d92f50d"}'
const authStr = decodeURI(path) + queryString + '\n' + body;
// 验签
const verifier = crypto.createVerify('md5WithRSAEncryption');
verifier.update(Buffer.from(authStr));
verifier.verify(pubKey, authorizationBase64, 'base64'); |
https://help.aliyun.com/document_detail/oss/practice/pc_web_upload/js_php_callback.html?spm=5176.docoss/practice/post_object_callback.2.3.nN7GWD
The text was updated successfully, but these errors were encountered: