### Starting uniCloud Service (Shell/Bash) Source: https://github.com/weiye465/unidocs-unicloud-zh/blob/master/docs/software/deploy.md Provides the command `./unicloud start` to initiate the uniCloud software edition service process from its installation root directory. Optional parameters like `-w` for specifying worker count and `--schedule` for enabling the timed task service can be added. ```Shell cd ${uniCloud_HOME} ./unicloud start ``` -------------------------------- ### Restarting uniCloud Service (Shell/Bash) Source: https://github.com/weiye465/unidocs-unicloud-zh/blob/master/docs/software/deploy.md Shows how to restart the uniCloud service by chaining the `./unicloud stop` command with `./unicloud start` using `&` to execute them sequentially from the installation root directory. This is often needed after deploying new code or updating configurations. ```Shell ./unicloud stop & ./unicloud start ``` -------------------------------- ### Synthesize GIF Animation Example URL Source: https://github.com/weiye465/unidocs-unicloud-zh/blob/master/docs/ext-storage/dev.md Example URL demonstrating how to combine multiple images into a GIF animation. It starts with the base URL of the first image and appends the animation operation (`animate`), duration (`duration/10`), and subsequent image keys (`merge/key`) using URL-safe Base64 encoding. ```URL Parameters https://web-ext-storage.dcloud.net.cn/unicloud/ext-storage/1.png?animate/duration/10/merge/key/dW5pY2xvdWQvZXh0LXN0b3JhZ2UvMi5wbmc=/key/dW5pY2xvdWQvZXh0LXN0b3JhZ2UvMy5wbmc= ``` -------------------------------- ### Initializing Cluster Space Config (Shell/Bash) Source: https://github.com/weiye465/unidocs-unicloud-zh/blob/master/docs/software/deploy.md Shows the commands to change directory to the uniCloud installation root and execute the `./unicloud create-config` command with the required service space ID (`-s [SpaceId]`) to generate the initial `config.json` configuration file. This step is necessary before starting the service. ```Shell cd ${uniCloud_HOME} ./unicloud create-config -s [SpaceId] ``` -------------------------------- ### Verifying uniCloud Service (Shell/Bash) Source: https://github.com/weiye465/unidocs-unicloud-zh/blob/master/docs/software/deploy.md Uses the `curl` command to send an HTTP request to `localhost:7001` to verify that the uniCloud service has started successfully and is responding. A successful response is indicated by the output `hello uniCloud`. ```Shell curl localhost:7001 ``` -------------------------------- ### Installing uniCloud Software Package (Shell/Bash) Source: https://github.com/weiye465/unidocs-unicloud-zh/blob/master/docs/software/deploy.md Demonstrates how to create a directory for the uniCloud software installation using `mkdir` and extract the downloaded tar.gz package into it using `tar -zxvf`. `${uniCloud_HOME}` is used as a placeholder for the chosen installation root directory, and `[version].tar.gz` is the name of the downloaded package file. ```Shell # 创建uniCloud安装目录,${uniCloud_HOME} 代指uni云开发软件版的安装根目录,如:mkdir ~/uniCloud mkdir ${uniCloud_HOME} # 解压安装包 tar -zxvf [version].tar.gz -C ${uniCloud_HOME} ``` -------------------------------- ### Decode Image Blind Watermark (V3) Example URL Source: https://github.com/weiye465/unidocs-unicloud-zh/blob/master/docs/ext-storage/dev.md Example URL demonstrating how to extract an image blind watermark using API version 3. It chains the encode operation URL with the decode operation (`|watermark/5/version/3/method/decode`) using the pipe symbol. ```URL Parameters https://web-ext-storage.dcloud.net.cn/unicloud/ext-storage/gogopher1.png?watermark/5/version/3/method/encode/imageKey/dW5pY2xvdWQvZXh0LXN0b3JhZ2UvdW5pQ2xvdWQucG5n|watermark/5/version/3/method/decode ``` -------------------------------- ### Decode Text Blind Watermark (V3) Example URL Source: https://github.com/weiye465/unidocs-unicloud-zh/blob/master/docs/ext-storage/dev.md Example URL demonstrating how to extract a text blind watermark using API version 3. It chains the encode operation URL with the decode operation (`|watermark/6/version/3/method/decode`) using the pipe symbol. ```URL Parameters https://web-ext-storage.dcloud.net.cn/unicloud/ext-storage/gogopher1.png?watermark/6/version/3/method/encode/text/MTIzNDU2|watermark/6/version/3/method/decode ``` -------------------------------- ### Encode Image Blind Watermark (V2) Example URL Source: https://github.com/weiye465/unidocs-unicloud-zh/blob/master/docs/ext-storage/dev.md Example URL demonstrating how to add an image blind watermark using API version 2. It appends the watermark operation (`watermark/5`), version (`version/2`), method (`method/encode`), and the URL-safe Base64 encoded watermark image key (`imageKey`) to the base image URL. ```URL Parameters https://web-ext-storage.dcloud.net.cn/unicloud/ext-storage/gogopher1.png?watermark/5/version/2/method/encode/imageKey/dW5pY2xvdWQvZXh0LXN0b3JhZ2UvdS5wbmc= ``` -------------------------------- ### Encode Text Blind Watermark (V2) Example URL Source: https://github.com/weiye465/unidocs-unicloud-zh/blob/master/docs/ext-storage/dev.md Example URL demonstrating how to add a text blind watermark using API version 2. It appends the watermark operation (`watermark/6`), version (`version/2`), method (`method/encode`), and the URL-safe Base64 encoded watermark text (`text`) to the base image URL. ```URL Parameters https://web-ext-storage.dcloud.net.cn/unicloud/ext-storage/gogopher1.png?watermark/6/version/2/method/encode/text/MTIzNDU2 ``` -------------------------------- ### Encode Image Blind Watermark (V3) Example URL Source: https://github.com/weiye465/unidocs-unicloud-zh/blob/master/docs/ext-storage/dev.md Example URL demonstrating how to add an image blind watermark using API version 3. It appends the watermark operation (`watermark/5`), version (`version/3`), method (`method/encode`), and the URL-safe Base64 encoded watermark image key (`imageKey`) to the base image URL. ```URL Parameters https://web-ext-storage.dcloud.net.cn/unicloud/ext-storage/gogopher1.png?watermark/5/version/3/method/encode/imageKey/dW5pY2xvdWQvZXh0LXN0b3JhZ2UvdW5pQ2xvdWQucG5n ``` -------------------------------- ### Encode Text Blind Watermark (V3) Example URL Source: https://github.com/weiye465/unidocs-unicloud-zh/blob/master/docs/ext-storage/dev.md Example URL demonstrating how to add a text blind watermark using API version 3. It appends the watermark operation (`watermark/6`), version (`version/3`), method (`method/encode`), and the URL-safe Base64 encoded watermark text (`text`) to the base image URL. ```URL Parameters https://web-ext-storage.dcloud.net.cn/unicloud/ext-storage/gogopher1.png?watermark/6/version/3/method/encode/text/MTIzNDU2 ``` -------------------------------- ### Scanning Server and Space Info (Shell/Bash) Source: https://github.com/weiye465/unidocs-unicloud-zh/blob/master/docs/software/deploy.md Explains how to run the `./unicloud scan` command from the installation directory to check the server environment, linked service space, and registration status for offline activation. If the server is unregistered, this command will output a hardware ID required for obtaining an offline license file. ```Shell ./uniCloud scan ``` -------------------------------- ### Decode Image Blind Watermark (V2) Example URL Source: https://github.com/weiye465/unidocs-unicloud-zh/blob/master/docs/ext-storage/dev.md Example URL demonstrating how to extract an image blind watermark using API version 2. It chains the encode operation URL with the decode operation, including the URL-safe Base64 encoded original image key (`orignal`) needed for version 2 decoding. ```URL Parameters https://web-ext-storage.dcloud.net.cn/unicloud/ext-storage/gogopher1.png?watermark/5/version/2/method/encode/imageKey/dW5pY2xvdWQvZXh0LXN0b3JhZ2UvdS5wbmc=|watermark/5/version/2/method/decode/orignal/dW5pY2xvdWQvZXh0LXN0b3JhZ2UvZ29nb3BoZXIxLnBuZw== ``` -------------------------------- ### Decode Text Blind Watermark (V2) Example URL Source: https://github.com/weiye465/unidocs-unicloud-zh/blob/master/docs/ext-storage/dev.md Example URL demonstrating how to extract a text blind watermark using API version 2. It chains the encode operation URL with the decode operation, including the URL-safe Base64 encoded original image key (`orignal`) needed for version 2 decoding. ```URL Parameters https://web-ext-storage.dcloud.net.cn/unicloud/ext-storage/gogopher1.png?watermark/6/version/2/method/encode/text/MTIzNDU2|watermark/6/version/2/method/decode/orignal/dW5pY2xvdWQvZXh0LXN0b3JhZ2UvZ29nb3BoZXIxLnBuZw== ``` -------------------------------- ### Initializing Ext Storage Manager JavaScript Source: https://github.com/weiye465/unidocs-unicloud-zh/blob/master/docs/ext-storage/dev.md Obtains an instance of the external storage manager object required for performing storage operations. It needs the provider and domain name. ```JavaScript const extStorageManager = uniCloud.getExtStorageManager({ provider: "qiniu", // 扩展存储供应商 domain: "example.com" // 域名地址 }); ``` -------------------------------- ### Installing uni-cloud-router using npm - Bash Source: https://github.com/weiye465/unidocs-unicloud-zh/blob/master/docs/uni-cloud-router.md Installs the uni-cloud-router package and saves it as a dependency in your uniCloud project's package.json using the npm package manager. ```Bash npm install --save uni-cloud-router ``` -------------------------------- ### Providing E-commerce Sample Data (JSON) Source: https://github.com/weiye465/unidocs-unicloud-zh/blob/master/docs/jql-operator-example.md Contains sample data entries for the 'goods', 'orders', and 'users' collections, illustrating the structure defined by the schema with example records including IDs, names, categories, prices, stock, purchase quantities, and dates. ```json // goods [ { "_id": "6363666826e8170001b62baa", "category": "手机", "name": "iPhone 14 512G", "price": 8488, "stock": 100 }, { "_id": "6363666f3aeb530001925bb6", "category": "手机", "name": "iPhone 13 Pro Max 128G", "price": 9688, "stock": 20 }, { "_id": "63636678a899370001a22627", "category": "手机", "name": "华为 Meta P50", "price": 7699, "stock": 50 }, { "_id": "63636681ff2a54000133afd7", "category": "手机", "name": "小米 12 Ultra", "price": 4599, "stock": 200 }, { "_id": "6363668cd69bc10001765c5f", "category": "电脑", "name": "红米 Redmibook 15寸 256G", "price": 3999, "stock": 100 }, { "_id": "6363669353a7f30001b46c84", "category": "电脑", "name": "Macbook Pro 512G", "price": 10499, "stock": 100 }, { "_id": "6363669a26e8170001b63213", "category": "电脑", "name": "Macbook Air 128G", "price": 7699, "stock": 100 } ] ``` ```json // orders [ { "_id": "6364b2e8b653d6000163c4f3", "buyNum": 2, "createDate": 1664769600000, "goodsId": "6363666826e8170001b62baa", "userId": "6364cc82b653d6000167f848" }, { "_id": "6364b2e8b653d6000163c4f4", "buyNum": 1, "createDate": 1664773200000, "goodsId": "6363668cd69bc10001765c5f", "userId": "6364cc82b653d6000167f848" }, { "_id": "6364b2e8b653d6000163c4f5", "buyNum": 2, "createDate": 1664758800000, "goodsId": "6363669353a7f30001b46c84", "userId": "6364cc82b653d6000167f849" }, { "_id": "6364b2e8b653d6000163c4f6", "buyNum": 1, "createDate": 1664769600000, "goodsId": "63636678a899370001a22627", "userId": "6364cc82b653d6000167f848" }, { "_id": "6364b2e8b653d6000163c4f7", "buyNum": 3, "createDate": 1664769600000, "goodsId": "63636681ff2a54000133afd7", "userId": "6364cc82b653d6000167f848" }, { "_id": "6364b2e8b653d6000163c4f8", "buyNum": 1, "createDate": 1664769600000, "goodsId": "6363668cd69bc10001765c5f", "userId": "6364cc82b653d6000167f849" }, { "_id": "6364b2e8b653d6000163c4f9", "buyNum": 3, "createDate": 1664683200000, "goodsId": "6363669353a7f30001b46c84", "userId": "6364cc82b653d6000167f848" }, { "_id": "6364b2e8b653d6000163c4fa", "buyNum": 2, "createDate": 1664679600000, "goodsId": "6363666f3aeb530001925bb6", "userId": "6364cc82b653d6000167f848" }, { "_id": "6364b2e8b653d6000163c4fb", "buyNum": 1, "createDate": 1664697600000, "goodsId": "63636678a899370001a22627", "userId": "6364cc82b653d6000167f849" } ] ``` ```json // users [ { "_id": "6364cc82b653d6000167f847", "name": "张三" }, { "_id": "6364cc82b653d6000167f848", "name": "李四" }, { "_id": "6364cc82b653d6000167f849", "name": "王五" } ] ``` -------------------------------- ### Frontend Upload using uni.uploadFile (uni-app) JavaScript Source: https://github.com/weiye465/unidocs-unicloud-zh/blob/master/docs/ext-storage/dev.md Client-side code for uni-app to select an image, call a backend cloud object to get upload parameters, and then use `uni.uploadFile` to upload the selected file directly to external storage. ```JavaScript uni.chooseImage({ count: 1, success: async (res) => { const filePath = res.tempFilePaths[0]; uni.showLoading({ title: "上传中...", mask: true }); // ext-storage-co 是你自己写的云对象(参考上面的云端代码) const uniCloudStorageExtCo = uniCloud.importObject("ext-storage-co"); const uploadFileOptionsRes = await uniCloudStorageExtCo.getUploadFileOptions({ cloudPath: `test/${Date.now()}.jpg` // 支持自定义目录 }); const uploadTask = uni.uploadFile({ ...uploadFileOptionsRes.uploadFileOptions, // 上传文件所需参数 filePath: filePath, // 本地文件路径 success: () => { const res = { cloudPath: uploadFileOptionsRes.cloudPath, // 文件云端路径 fileID: uploadFileOptionsRes.fileID, // 文件ID fileURL: uploadFileOptionsRes.fileURL // 文件URL(如果是私有权限,则此URL是无法直接访问的) }; // 数据库里可直接保存 fileURL 或 fileID console.log("上传成功", res); }, fail: (err) => { console.log("上传失败", err); } }); // 监听上传进度 uploadTask.onProgressUpdate((res) => { console.log("监听上传进度", res); }); uni.hideLoading(); } }); ``` -------------------------------- ### uni-cloud-router Directory Structure Example - Bash Source: https://github.com/weiye465/unidocs-unicloud-zh/blob/master/docs/uni-cloud-router.md Illustrates the typical file structure for a uniCloud cloud function utilizing uni-cloud-router, including the main entry file, configuration, controller, and an optional service layer. ```Bash ├── package.json ├── index.js // 云函数入口文件 ├── config.js // 用于配置 router 应用根目录、中间件等 ├── controller // 用于解析用户的输入,处理后返回相应的结果 | ├── user.js ├── service (可选) //用于编写业务逻辑层,建议使用 | ├── user.js ``` -------------------------------- ### Frontend Upload using uni.uploadFile (uni-app x) UTS Source: https://github.com/weiye465/unidocs-unicloud-zh/blob/master/docs/ext-storage/dev.md Client-side code for uni-app x to select an image, call a backend cloud object to get upload parameters, and then use `uni.uploadFile` to upload the selected file, demonstrating Promise handling and UTS type casting. ```UTS uni.chooseImage({ count: 1, success: (res) => { const filePath = res.tempFilePaths[0]; uni.showLoading({ title: "上传中...", mask: true }); // ext-storage-co 是你自己写的云对象(参考上面的云端代码) const uniCloudStorageExtCo = uniCloud.importObject("ext-storage-co"); uniCloudStorageExtCo.getUploadFileOptions({ cloudPath: `test/${Date.now()}.jpg` // 支持自定义目录 }).then((uploadFileOptionsRes : UTSJSONObject) => { const uploadFileOptions = uploadFileOptionsRes['uploadFileOptions'] as UTSJSONObject; const url = uploadFileOptions['url'] as string; const name = uploadFileOptions['name'] as string; const formData = uploadFileOptions['formData'] as UTSJSONObject; const cloudPath = uploadFileOptionsRes['cloudPath'] as string; // 文件云端路径 const fileID = uploadFileOptionsRes['fileID'] as string; // 文件ID const fileURL = uploadFileOptionsRes['fileURL'] as string; // 文件URL(如果是私有权限,则此URL是无法直接访问的) const uploadTask = uni.uploadFile({ url, name, formData, filePath, success: () => { const uploadRes = { cloudPath, fileID, fileURL }; // 数据库里可直接保存 fileURL 或 fileID console.log("上传成功", uploadRes); }, fail: (err) => { console.log("上传失败", err); } }); // 监听上传进度 uploadTask.onProgressUpdate((res) => { console.log("监听上传进度", res); }); uni.hideLoading(); }); } }); ``` -------------------------------- ### Writing a Uni-cloud-router Service with Context - JavaScript Source: https://github.com/weiye465/unidocs-unicloud-zh/blob/master/docs/uni-cloud-router.md Provides an example of a service class method (`create`) extending `Service`. It demonstrates accessing `this.db`, which is equivalent to `uniCloud.database()`, within the service to perform database operations, showing how services encapsulate data access and business logic. ```JavaScript // service/post.js const Service = require("uni-cloud-router").Service; // 必须继承 Service module.exports = class PostService extends Service { async create(data) { return this.db.add(data); } }; ``` -------------------------------- ### Full JQL getTreePath Query Example (JavaScript) Source: https://github.com/weiye465/unidocs-unicloud-zh/blob/master/docs/jql.md This JavaScript code provides a complete example of querying the 'department' collection to retrieve the path from the root down to a specific node using `getTreePath`. It includes standard Promise handling and specifies the target node using the `startWith` parameter. ```javascript db.collection("department").get({ getTreePath: { "startWith": "_id=='5fe77232974b6900018c6cb1'" } }) .then((res) => { const treepath = res.result.data console.log("treepath", treepath); }).catch((err) => { uni.showModal({ content: err.message || '请求服务失败', showCancel: false }) }).finally(() => { uni.hideLoading() // console.log("finally") }) ``` -------------------------------- ### JQL Basic Get Query - JavaScript Source: https://github.com/weiye465/unidocs-unicloud-zh/blob/master/docs/jql.md Demonstrates a simple query using the JQL syntax `where('name == "hello-uni-app"')`. It retrieves documents from the 'list' collection where the 'name' field is exactly "hello-uni-app". The example shows the basic `.get()`, `.then()`, and `.catch()` structure for handling query results and errors. ```JavaScript // 注意,此处的db是通过 uniCloud.databaseForJQL() 得到,而不是 uniCloud.database() const db = uniCloud.databaseForJQL() // 使用`jql`查询list表内`name`字段值为`hello-uni-app`的记录 db.collection('list') .where('name == "hello-uni-app"') .get() .then((res)=>{ // res 为数据库查询结果 }).catch((err)=>{ // err.message 错误信息 // err.code 错误码 }) ``` -------------------------------- ### Full JQL getTree Query Example (JavaScript) Source: https://github.com/weiye465/unidocs-unicloud-zh/blob/master/docs/jql.md This JavaScript code provides a complete example of querying a 'department' collection to retrieve tree-structured data using `getTree: {}`. It includes standard Promise handling with `.then()`, `.catch()`, and `.finally()` for processing the results or errors. ```javascript db.collection("department").get({ getTree: {} }) .then((res) => { const resdata = res.result.data console.log("resdata", resdata); }).catch((err) => { uni.showModal({ content: err.message || '请求服务失败', showCancel: false }) }).finally(() => { }) ``` -------------------------------- ### Getting Frontend Upload Options in Cloud Object JavaScript Source: https://github.com/weiye465/unidocs-unicloud-zh/blob/master/docs/ext-storage/dev.md Defines a cloud object method `getUploadFileOptions` that retrieves the necessary parameters for frontend file uploads using `uni.uploadFile`. It allows performing custom logic like permission checks before generating the options. ```JavaScript module.exports = { getUploadFileOptions(data = {}) { let { cloudPath, // 前端传过来的文件路径 } = data; // 可以在此先判断下此路径是否允许上传等逻辑 // ... // 然后获取 extStorageManager 对象实例 const extStorageManager = uniCloud.getExtStorageManager({ provider: "qiniu", domain: "example.com" // 域名地址 }); // 最后调用 extStorageManager.getUploadFileOptions let uploadFileOptionsRes = extStorageManager.getUploadFileOptions({ cloudPath: cloudPath, allowUpdate: false // 是否允许覆盖更新,如果返回前端,建议设置false,代表仅新增,不可覆盖 }); return uploadFileOptionsRes; } } ``` -------------------------------- ### Querying Database with clientDB API - JavaScript Source: https://github.com/weiye465/unidocs-unicloud-zh/blob/master/docs/cf-functions.md Demonstrates how to directly interact with the uniCloud database from the client side using the clientDB API. It shows how to get a database reference, select a collection, perform a query, and handle the promise-based response. ```JavaScript const db = uniCloud.database() // 获取云数据库的引用 db.collection('list').get() .then((res)=>{ // res 为数据库查询结果 }).catch((err)=>{ console.log(err); }) ``` -------------------------------- ### Example SQL Select Query Source: https://github.com/weiye465/unidocs-unicloud-zh/blob/master/docs/jql.md Shows a basic SQL query to select all fields from 'table1' where 'field1' equals "value1". This snippet is presented as a comparison point to contrast traditional SQL syntax with NoSQL and JQL. ```SQL select * from table1 where field1="value1" ``` -------------------------------- ### Configuring CORS (JSON) Source: https://github.com/weiye465/unidocs-unicloud-zh/blob/master/docs/software/deploy.md Provides a JSON snippet for configuring Cross-Origin Resource Sharing (CORS) within the uniCloud software edition `config.json`. It specifies allowed origins (using `*` for all) and permitted HTTP methods (`GET`, `POST`, etc.) for cross-origin requests. ```JSON { "cors": { "origin": ["*"], "allowMethods": ["GET", "POST", 'PUT', 'DELETE', 'HEAD', 'OPTIONS', 'PATCH' ] } } ``` -------------------------------- ### Starting Facial Recognition Verification in uni-app Source: https://github.com/weiye465/unidocs-unicloud-zh/blob/master/docs/frv/dev.md Initiates the facial recognition verification UI on the client side. It requires a certifyId obtained from the server. Optional parameters can configure the progress bar color and screen orientation. Success, fail, and complete callbacks handle the outcome. ```JavaScript uni.startFacialRecognitionVerify({ certifyId:"", progressBarColor: "#CC0000", //刷脸圈的颜色 screenOrientation: "port", //认证界面UI朝向 success:(e)=>{ console.log(JSON.stringify(e)) }, fail:(e)=>{ console.log(JSON.stringify(e)) }, complete:(e)=>{ console.log(JSON.stringify(e)) } }) ``` -------------------------------- ### Cloud Uploading File from Base64 JavaScript Source: https://github.com/weiye465/unidocs-unicloud-zh/blob/master/docs/ext-storage/dev.md Shows how to convert a Base64 encoded string into a Buffer and then upload the binary content to external storage using `extStorageManager.uploadFile`. ```JavaScript const extStorageManager = uniCloud.getExtStorageManager({ provider: "qiniu", domain: "example.com" // 域名地址 }); // 文件的base64值 let base64 = `data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEgAAABICAYAAABV7bNHAAAAAXNSR0IArs4c6QAAAX1JREFUeF7tnLFxwkAQRf86dEwHDqEATAeO3YNdgmugBFGDiemAoQBSd+DUhD6Pxk6Y4XTB13o08AiFDt09vf3cCGZDkhbd6qHoey3Fk6T7/tgNv05S2YXu3o6v+4/4haODVGY3DOXC0uMzpGXMu+W7FM/AuUSgbGPePX5RVlU9Tj2ggj11AgBq2AEgAHkBgkEYhEEeAQzy+JFBGIRBHgEM8fiRQRg0AYOOL/vqLBablTfDx2jsa49SYtmTHGKUfW0A/UcGZd9FDDJSKvvmUGKUmKGnJAzCIAxK3aRSYpQYJUaJsZM2qoCdNI87DH0kYRAGYZBHAIM8fmQQBmGQRwCDPH5kEAZhkEcAgzx+ZBAGYZBH4NoNSqXT+PAx/puU/rMPgBpP9QAEoLYDQ3uR9ui8M8ggQtqzazIGecuY9uhRvuanvURvdgBq8AMQgCgxjwAGefzIIAzCII8ABnn8aLA0zK9vsESLrjqjsqXJW5XOX5O3/n3aBJ5ROmsT+AM4B3/QCW75sQAAAABJRU5ErkJggg==`; let base64Str = "base64,"; let base64Index = base64.indexOf(base64Str); if (base64Index > -1) base64 = base64.substring(base64Index + base64Str.length); let fileContent = new Buffer(base64, 'base64'); let res = await extStorageManager.uploadFile({ cloudPath: `${Date.now()}.png`, // 云端文件名,不填则自动生成 fileContent, // 要上传的文件内容 allowUpdate: false // 是否允许覆盖 }); console.log('uploadFile: ', res); ``` -------------------------------- ### Querying Data (Traditional NoSQL) - uniCloud clientDB - JavaScript Source: https://github.com/weiye465/unidocs-unicloud-zh/blob/master/docs/clientdb.md This snippet shows how to get a database reference using `uniCloud.databaseForJQL()` and perform a traditional MongoDB-style query on a collection. It demonstrates setting a `where` condition and handling the promise resolution for query results or errors. ```JavaScript // 获取db引用 const db = uniCloud.databaseForJQL() //代码块为cdb db.collection('list') .where({ name: "hello-uni-app" //传统MongoDB写法,不是jql写法。实际开发中推荐使用jql写法 }).get() .then((res)=>{ // res 为数据库查询结果 }).catch((err)=>{ console.log(err.code); // 打印错误码 console.log(err.message); // 打印错误内容 }) ``` -------------------------------- ### Using Promise and Async/Await with uniCloud.callFunction in Vue Source: https://github.com/weiye465/unidocs-unicloud-zh/blob/master/docs/faq.md This Vue component snippet demonstrates how to handle asynchronous API calls using `uniCloud.callFunction`. It shows two methods: `testThen` utilizes the standard Promise `.then().catch()` syntax for handling success and error, while `testAwait` uses the `async/await` syntax for a more synchronous-looking flow, with a commented-out example of error handling using `try...catch`. It shows how to integrate these patterns within Vue methods reacting to button clicks. ```javascript // index.vue