作者:俏巴
概述
IoT Studio服务开发是一个物联网业务逻辑的开发工具,通过编排服务节点的方式快速完成简单的物联网业务逻辑的设计。本文演示如何使用NodeJS节点基于OSS NodeJS SDK操作阿里云OSS存储服务。
Step By Step
1、拖拽服务开发控件
2、安装ali-oss
3、编写NodeJs脚本
/**
@param {Object} payload 上一节点的输出@param {Object} node 指定某个节点的输出@param {Object} query 服务流第一个节点的输出@param {Object} context { appKey, appSecret }
*/
module.exports = async function(payload, node, query, context) {
<span class="hljs-comment">// const result;</span>
<span class="hljs-keyword">let</span> OSS = <span class="hljs-built_in">require</span>(<span class="hljs-string">'ali-oss'</span>);
<span class="hljs-comment">// region https://help.aliyun.com/document_detail/31837.html?spm=a2c4g.11186623.2.16.92f62d71f1LTZo#concept-zt4-cvy-5db</span>
<span class="hljs-comment">// accessKeyId,accessKeySecret https://yq.aliyun.com/articles/693979</span>
<span class="hljs-keyword">let</span> client = <span class="hljs-keyword">new</span> OSS({
region: <span class="hljs-string">'oss-cn-hangzhou'</span>,
accessKeyId: <span class="hljs-string">'LTAIOZZg********'</span>,
accessKeySecret: <span class="hljs-string">'v7CjUJCMk7j9aKduMAQLjy********'</span>
});
<span class="hljs-keyword">try</span> {
<span class="hljs-comment">// 列举存储空间</span>
<span class="hljs-keyword">let</span> result = <span class="hljs-keyword">await</span> client.listBuckets();
<span class="hljs-built_in">console</span>.log(result);
<span class="hljs-keyword">return</span> result;
} <span class="hljs-keyword">catch</span> (err) {
<span class="hljs-built_in">console</span>.log(err);
}
}
4、部署调试