当前位置: 首页 > wzjs >正文

手机建网站花钱吗东莞品牌网站制作

手机建网站花钱吗,东莞品牌网站制作,网站专题页功能,网站如何做背景音乐一、端侧调用云存储上传头像 云存储是一种可伸缩、免维护的云端存储服务,可用于存储图片、音频、视频或其他由用户生成的内容。借助云存储服务,您可以无需关心存储服务器的开发、部署、运维、扩容等事务,大大降低了应用使用存储的门槛&#…

一、端侧调用云存储上传头像

云存储是一种可伸缩、免维护的云端存储服务,可用于存储图片、音频、视频或其他由用户生成的内容。借助云存储服务,您可以无需关心存储服务器的开发、部署、运维、扩容等事务,大大降低了应用使用存储的门槛,让您可以专注于应用的业务能力构建,助力您的商业成功。

云存储提供了客户端和服务端SDK,您可以使用云存储SDK为您的应用实现安全可靠的文件上传和下载服务,同时具备如下优势。

  • 安全可靠:全流程使用HTTPS协议对用户的传输数据进行加密保护,并采用安全的加密协议将文件加密存储在云端。
  • 断点续传:因网络原因或用户原因导致的操作中止,只需要简单地传入操作中止的位置,就可以尝试重新开始该操作。
  • 可伸缩:提供EB级的数据存储,解决海量数据存储的难题。
  • 易维护:通过简单的判断返回异常就可以定位出错误原因,定位快捷方便。

云存储模块提供使用云存储对文件进行上传、下载、查询和删除等操作能力。以上传宝宝头像为例,端侧调用云存储需要以下操作步骤:

1)引入云存储模块

import {cloudStorage} from '@kit.CloudFoundataionKit';
import { BusinessError, request } from '@kit.BasicServicesKit';

2)初始化云存储实例

const bucket: cloudStorage.StorageBucket = cloudStorage.bucket();

3)调用云存储上传接口,上传图片

bucket.uploadFile(getContext(this), {localPath: cacheFilePath,cloudPath: cloudPath
})

4)调用云存储获取图片地址接口

bucket.getDownloadURL(cloudPath).then((downloadURL: string) => {this.imageUrl = downloadURL;
})

完整代码:

import { cloudFunction, cloudDatabase, cloudStorage } from '@kit.CloudFoundationKit';
import { BusinessError, request } from '@kit.BasicServicesKit';
import { SymbolGlyphModifier } from '@kit.ArkUI';import { Feeding } from '../model/Feeding';
import { fileIo } from '@kit.CoreFileKit';
import { photoAccessHelper } from '@kit.MediaLibraryKit';const bucket: cloudStorage.StorageBucket = cloudStorage.bucket();
type UploadCompleteCallback = (uploadSuccess: boolean) => void;interface BabyAge {years: number;months: number;days: number;totalDays: number;
}interface ResponseBody {code: number;desc: string;data: BabyAge
}@Entry
@Component
struct Index {controller: SearchController = new SearchController();@State birthday: string = "";@State callFunctionResult: BabyAge | undefined = undefined;currentDateTime: Date = new Date();condition: cloudDatabase.DatabaseQuery<Feeding> = new cloudDatabase.DatabaseQuery(Feeding);private databaseZone = cloudDatabase.zone("default");@State allFeedingList: Feeding[] = [];@State feeding: Feeding = new Feeding();@State isFeeding: boolean = false;@State startTime: Date = new Date();@State imageUrl: string | ResourceStr = $r('app.media.empty_image');// 查询当前喂养记录信息async queryAllFeeding() {try {// 构建查询条件const queryCondition = this.condition.greaterThanOrEqualTo("startTime", this.currentDateTime.setHours(0, 0, 0, 0)).and().lessThanOrEqualTo("startTime", this.currentDateTime.setHours(23, 59, 59, 999));const result = await this.databaseZone.query(queryCondition);if (result.length > 0) {this.allFeedingList = result;}} catch (error) {// 异常处理this.allFeedingList = [];}}// 新增喂养记录async insertFeeding(feeding: Feeding) {await this.databaseZone.upsert(feeding);await this.queryAllFeeding();}// 删除数据async deleteFeeding(feeding: Feeding) {try {await this.databaseZone.delete(feeding);await this.queryAllFeeding();} catch (error) {const err: BusinessError = error;this.getUIContext().getPromptAction().showToast({message: err.message})}}async aboutToAppear(): Promise<void> {this.queryAllFeeding();}build() {Column({ space: 10 }) {Text("请先设置宝宝出生日期").fontColor(Color.Grey).height(54)Search({ controller: this.controller, value: this.birthday }).width('90%').height('54vp').searchIcon(new SymbolGlyphModifier($r('sys.symbol.calendar_badge_play')).fontColor([Color.Grey]).fontSize('30fp')).cancelButton({style: CancelButtonStyle.INVISIBLE}).borderRadius('8vp').onClick(() => {CalendarPickerDialog.show({selected: new Date(this.birthday),acceptButtonStyle: {style: ButtonStyleMode.EMPHASIZED},cancelButtonStyle: {fontColor: Color.Grey},onAccept: async (value) => {this.birthday = value.toLocaleDateString();console.info("calendar onAccept:" + JSON.stringify(value))let result: cloudFunction.FunctionResult = await cloudFunction.call({name: 'calculate-baby-age',version: '$latest',timeout: 10 * 1000,data: {birthday: this.birthday}});let body = result.result as ResponseBody;this.callFunctionResult = body.data;}})})if (this.callFunctionResult !== undefined) {Row() {Column({ space: 8 }) {Image(this.imageUrl).width(64).height(64).borderRadius(16).onClick(() => {this.upLoadImage();})Text(`我已经${this.callFunctionResult.years}岁了 ${this.callFunctionResult.months}${this.callFunctionResult.days}天了~`)Text(`我已经出生${this.callFunctionResult.totalDays}天了~`)}.width('100%')}.width('90%')Button(`${this.isFeeding ? '停止喂养' : '开始喂养'}`).backgroundColor(this.isFeeding ? Color.Orange : Color.Green).onClick(async () => {this.isFeeding = !this.isFeeding;if (this.isFeeding) {this.startTime = new Date();this.feeding.id = this.allFeedingList.length + 1;this.feeding.startTime = this.startTime;} else {this.feeding.totalDuration = new Date().getTime() - this.startTime.getTime();await this.insertFeeding(this.feeding);}})if (this.allFeedingList.length > 0) {List() {ForEach(this.allFeedingList, (item: Feeding) => {ListItem() {Column({ space: 8 }) {Row() {Text(`${item.type}喂养`)Text(`${item.startTime.toLocaleDateString()}`)}.width('100%').height(32).justifyContent(FlexAlign.SpaceBetween)Text(`总喂养时长:${item.totalDuration >= (60 * 1000) ? (item.totalDuration / (60 * 1000)) + 'm' : (item.totalDuration / 1000) + 's'}`).width('100%').height(32)Row() {Button("删除").onClick(async () => {this.getUIContext().getPromptAction().showDialog({title: '温馨提示',message: '确定要删除该喂养记录吗?',buttons: [{text: '取消',color: '#D3D3D3'},{text: '确定',color: '#FF5277'}],}).then(async data => {console.info('showDialog success, click button: ' + data.index);if (data.index === 1) {await this.deleteFeeding(item);}}).catch((err: Error) => {console.info('showDialog error: ' + err);})})}.width('100%')}.backgroundColor(0xf2f2f2).padding(12).borderRadius(8)}})}.width('90%').height(450).divider({strokeWidth: 2,color: Color.White})}}}.width('100%').height('100%')}private upLoadImage() {this.selectImage().then((selectImageUri: string) => {if (!selectImageUri) {return;}this.initStates();// copy select file to cache directoryconst fileName = selectImageUri.split('/').pop() as string;const cacheFilePath = `${getContext().cacheDir}/${fileName}`;this.copyFile(selectImageUri, cacheFilePath);const cloudPath = `default-bucket-lg41j/image_${new Date().getTime()}.jpg`;bucket.uploadFile(getContext(this), {localPath: cacheFilePath,cloudPath: cloudPath}).then(task => {// add task event listenerthis.addEventListener(task, this.onUploadCompleted(cloudPath, cacheFilePath));// start tasktask.start().catch((err: BusinessError) => {});}).catch((err: BusinessError) => {});}).catch((err: Error) => {});}private async selectImage(): Promise<string> {return new Promise((resolve: (selectUri: string) => void, reject: (err: Error) => void) => {const photoSelectOptions = new photoAccessHelper.PhotoSelectOptions();// 过滤选择媒体文件类型为IMAGEphotoSelectOptions.MIMEType = photoAccessHelper.PhotoViewMIMETypes.IMAGE_TYPE;photoSelectOptions.maxSelectNumber = 1;new photoAccessHelper.PhotoViewPicker().select(photoSelectOptions).then((photoSelectResult: photoAccessHelper.PhotoSelectResult) => {resolve(photoSelectResult.photoUris[0]);}).catch((err: Error) => {reject(err);});});}private addEventListener(task: request.agent.Task, completeCallback: UploadCompleteCallback) {task.on('progress', (progress) => {});task.on('completed', (progress) => {completeCallback(true);});task.on('response', (response) => {});task.on('failed', (progress) => {completeCallback(false);});}private onUploadCompleted(cloudPath: string, cacheFilePath: string) {return (uploadSuccess: boolean) => {if (uploadSuccess) {bucket.getDownloadURL(cloudPath).then((downloadURL: string) => {this.imageUrl = downloadURL;}).catch((err: BusinessError) => {});}// delete cache file when task finishedfileIo.unlink(cacheFilePath).catch((err: BusinessError) => {});};}private copyFile(src: string, dest: string) {const srcFile = fileIo.openSync(src);const dstFile = fileIo.openSync(dest, fileIo.OpenMode.READ_WRITE | fileIo.OpenMode.CREATE);fileIo.copyFileSync(srcFile.fd, dstFile.fd);fileIo.closeSync(srcFile);fileIo.closeSync(dstFile);}private initStates() {this.imageUrl = $r('app.media.empty_image');}
}

二、课程总结

通过十小节课程的学习,相信大家已经完全掌握了端云一体化开发流程,能够独立完成云函数开发、调试、部署、以及调用,独立完成云数据库设计、开发、部署、以及调用,以及云存储的端侧调用。


文章转载自:

http://UIR1NhgS.cjwkf.cn
http://KvfTc6ZT.cjwkf.cn
http://yaPra44Q.cjwkf.cn
http://Fo5pcyGE.cjwkf.cn
http://QoD9kSn8.cjwkf.cn
http://R1ievcbZ.cjwkf.cn
http://2t7Cq7Uh.cjwkf.cn
http://kksQ0xUJ.cjwkf.cn
http://LZkwx65T.cjwkf.cn
http://U1DHTz7F.cjwkf.cn
http://JzIpkoMo.cjwkf.cn
http://OgBACdPV.cjwkf.cn
http://Vv2N9pGp.cjwkf.cn
http://rG1N7owq.cjwkf.cn
http://zNeba2Yi.cjwkf.cn
http://nRRU6Wkq.cjwkf.cn
http://MnE1maqz.cjwkf.cn
http://f0bA523d.cjwkf.cn
http://75aWRZsN.cjwkf.cn
http://gZrmkYfT.cjwkf.cn
http://NYoWtT6F.cjwkf.cn
http://Ynrydcyi.cjwkf.cn
http://1FaLUCFN.cjwkf.cn
http://qkZTvwCu.cjwkf.cn
http://7QmKysTW.cjwkf.cn
http://CIAle6XE.cjwkf.cn
http://rQZsa3p8.cjwkf.cn
http://hhkhPTtA.cjwkf.cn
http://7HKrC08J.cjwkf.cn
http://2crj287Y.cjwkf.cn
http://www.dtcms.com/wzjs/683193.html

相关文章:

  • 网站交换链接的网络营销意义小视频网站开发
  • 贵阳市住房城乡建设局官方网站影视公司简介
  • 网站手机端跳转页面模板软件开发培训课件
  • 长春的网站建设山东装饰公司网站建设公司
  • 做公司做网站有用吗徐州关键字优化公司
  • 四会城乡建设局网站网站建设与推广策划书
  • 做招聘网站需要什么wordpress mysql 引擎
  • 网站系统介绍江苏住房城乡建设厅网站
  • 桂林北站到阳朔天津中小企业网站制作
  • 东高端莞商城网站建设网站建设模板怎么做
  • 云南做网站公司网站建设评选打分
  • 南阳网站改版搭建网站 网页
  • 网站主办单位负责人手机版网站模板 免费下载
  • 最简单的做网站工具怎么做微信网站吗
  • 网站设计哪家便宜wordpress中国能用吗
  • 中山教育平台网站建设中铁建设集团有限公司是央企吗
  • 企业在建设银行网站怎么发工资做选择网站
  • 做班级网站的实训报告开发微信微商城
  • 公司网站建设制作商网站建设医药
  • 页面设计培训学什么网站查询工具seo
  • 彩票游戏网站开发泰安手机网站建设公司
  • 沈阳企业网站排名优化网站设计外包合同
  • 2003总是说网站建设中支持支付宝登录的网站建设
  • 网站建设怎么打开简繁英3合1企业网站生成管理系统
  • 怎么做flash网站商城网站如何设计
  • 网站后台模板免费网络营销推广方法范文
  • 网站搭建东莞沈阳seo按天计费
  • 个人网站制作的主要内容运行wordpress环境
  • jsp网站开发教学视频教程用vps安装Wordpress
  • 免费网站后台管理系统htmlwordpress外链转內链