<template> <button @click="changeMessage">选择文件</button> <view v-show="false" :path="path" :change:path="requestModule.uploadOBS"></view> </template> <script setup> import { ref } from 'vue' import { getCurrentInstance } from 'vue' const { proxy } = getCurrentInstance() // 把回调挂到实例上,renderjs 就能通过 callMethod 调到 proxy.$onRenderData = (data) => { console.error('str:', data) } const path = ref(null) const changeMessage = () => { uni.chooseImage({ count: 1, // 最多选择数量 sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图 sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机 success: async (res) => { // tempFilePath 可以作为 img 标签的 src 属性显示图片 const tempFilePaths = res.tempFilePaths path.value = tempFilePaths[0]; }, fail: (err) => { console.error('选择图片失败:', err) } }) } </script> <script> // 专门给 renderjs 回调用 ownerVm.callMethod('onRenderData', "999999") 就能调到 /* export default { methods: { onRenderData(data) { console.error('str:', data) } } } */ </script> <script module="requestModule" lang="renderjs"> export default { methods: { /* 1. 逻辑层 → renderjs */ uploadOBS(newVal, oldVal, ownerVm, vm) { console.error('path:', newVal) this.getFileAsArrayBuffer2(newVal).then(res => { console.error('arrayBuffer:', res) return this.uploadArrayBuffer(res,'https://jszj-dev.obs.cn-east-3.myhuaweicloud.com/2011725287372374017/jszj_lp_merchant_apply_for_application_materials_file_id/20260116/1762482093185_1768566856106.jpg?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Date=20260116T123416Z&X-Amz-SignedHeaders=host&X-Amz-Credential=HPUAACHPJ15SJKPZGOAP%2F20260116%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Expires=86400&X-Amz-Signature=29eb09d67a7bf73afb199e75148c57d73d13d65146fe6bd351b479cc0ebd66d1','image/jpeg'); }).then(res => { console.error('upload:', res) }).catch(err => { }) //调用vue2方法 //ownerVm.callMethod('onRenderData', "999999") //调用vue3方法 ownerVm.callMethod('$onRenderData', "999999") }, getFileAsArrayBuffer2(filePath) { return new Promise((resolve, reject) => { const xhr = new XMLHttpRequest() xhr.open('GET', filePath, true) xhr.responseType = 'arraybuffer' xhr.onload = function() { if (xhr.status === 200) { resolve(xhr.response) } else { reject(new Error('Failed to load file')) } } xhr.onerror = function() { reject(new Error('Network error')) } xhr.send() }) }, uploadArrayBuffer(arrayBuffer, uploadUrl, fileType = 'application/octet-stream') { return new Promise((resolve, reject) => { const xhr = new XMLHttpRequest(); /* 1. 打开连接 */ xhr.open('PUT', uploadUrl, true); /* 2. 设置请求头 */ xhr.setRequestHeader('Content-Type', fileType); /* 3. 响应类型(按需要) */ xhr.responseType = 'arraybuffer'; /* 4. 上传进度 */ xhr.upload.onprogress = function(e) { if (e.lengthComputable) { const percent = (e.loaded / e.total) * 100; console.log('上传进度:', percent.toFixed(2) + '%'); } }; /* 5. 成功/失败 */ xhr.onload = function() { if (xhr.status >= 200 && xhr.status < 300) { resolve(xhr.response); // 服务端返回的 ArrayBuffer } else { reject(new Error(`上传失败 ${xhr.status}`)); } }; xhr.onerror = () => reject(new Error('网络错误')); /* 6. 发送二进制 */ xhr.send(arrayBuffer); }); } } } </script> <style> </style>uniapp 使用 XMLHttpRequest发送二进制上传文件 可使用预上传接口上传到华为obs
张小明
前端开发工程师
树莓派4多系统启动盘制作:NOOBS完整指南
一卡多系统:手把手教你用 NOOBS 玩转树莓派4的无限可能 你有没有过这样的经历? 想在树莓派上试试 Ubuntu Mate 的桌面体验,结果刚刷完卡,又想起还得跑个 Python 脚本——那得换回 Raspberry Pi OS。于是拔卡、烧录、再插回去………
Qwen2.5-7B-Instruct教育培训:个性化学习系统
Qwen2.5-7B-Instruct教育培训:个性化学习系统 1. 技术背景与应用场景 随着人工智能技术的快速发展,大语言模型在教育领域的应用逐渐深入。传统教学模式难以满足学生多样化的学习需求,而基于大语言模型的个性化学习系统能够根据学生的知识水…
无需PS!CV-UNet Universal Matting镜像实现智能抠图
无需PS!CV-UNet Universal Matting镜像实现智能抠图 1. 引言:AI驱动的智能抠图新时代 在数字内容创作日益普及的今天,图像背景移除(即“抠图”)已成为设计师、电商运营、自媒体创作者等群体的高频需求。传统依赖Phot…
DLSS Swapper:解锁游戏画质调校的终极利器
DLSS Swapper:解锁游戏画质调校的终极利器 【免费下载链接】dlss-swapper 项目地址: https://gitcode.com/GitHub_Trending/dl/dlss-swapper 还在为游戏更新后画质突然变差而困扰吗?当最新DLSS版本反而让心爱的游戏画面失真时,DLSS S…
从零开始学ARM开发:小白也能懂的手把手教程
从零点亮第一颗LED:一个嵌入式萌新的ARM开发入门实录 你还记得自己写的第一个程序是什么吗? 对很多人来说,是屏幕上那一行简单的 Hello, World! 。 而在嵌入式的世界里,我们的“Hello World”,是一颗闪烁的LED。 …
DeepSeek-R1-Distill-Qwen-1.5B数学可视化:图表与公式协同生成
DeepSeek-R1-Distill-Qwen-1.5B数学可视化:图表与公式协同生成 1. 引言 1.1 技术背景与应用场景 随着大模型在数学推理、代码生成和逻辑推导等复杂任务中的表现不断提升,如何将抽象的数学思维过程以直观、可交互的方式呈现,成为提升用户体…