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

学习bug

2025.8.6,在发帖功能中,一直出现上传的图片页面无法上传的问题,bucket中有上传的图片,但是数据库中的image_url一直为空,复制up的源码也没有用
​记录一下我的解决办法
​export const uploadFile = async (image_key: string, file: ImageResult) => {

try {

const res = await storage.createFile('689318ae002bdaf1ece1', image_key, {

name: image_key,

type: 'image/jpeg',

size: file.height * file.width,

uri: file.uri,

});

const fileId = res.$id;

//  手动拼接图片 URL

const endpoint = 'https://cloud.appwrite.io/v1';

const projectId = 'XXX';

const bucketId = 'XXX';

const fileUrl = `${endpoint}/storage/buckets/${bucketId}/files/${fileId}/view?project=${projectId}&mode=admin`;

return {

fileId,

fileUrl,

};

} catch (error) {

console.log('uploadFile error:', error);

throw error;

}

};

​const pickImage = async () => {

try {


let result = await ImagePicker.launchImageLibraryAsync({

mediaTypes: ["images", "videos"],

allowsEditing: true,

aspect: [4, 3],

quality: 1,

});

if (!result.canceled) {

const compressedImage = await compressImage(result.assets[0].uri);

if (compressedImage) {

if (!compressedImage) {

Alert.alert("图片压缩失败");

return;

}

const { fileId, fileUrl } = await uploadFile(

ID.unique(),

compressedImage

);

if (!fileUrl) {

Alert.alert("图片上传失败");

return;

}

setImage(fileUrl);

}

}

} catch (error) {

console.log(error);

Alert.alert("图片选择失败");

}

};

​希望能帮助后来的朋友😘👌

http://www.xdnf.cn/news/17293.html

相关文章:

  • 力扣热题100------136.只出现一次的数字
  • 机器学习之朴素贝叶斯
  • Unix/Linux 系统编程中用于管理信号处理行为的核心概念或模型
  • Dart语言“跨界”指南:从JavaScript到Kotlin,如何用多语言思维快速上手
  • 【CSS】动态修改浏览器滚动条宽度
  • PCL 平面特征点提取
  • IntelliJ IDEA 2025.1.4.1 中文版
  • Sklearn 机器学习 数据聚类 DBSCAN聚类算法的异常点
  • 在 Visual Studio Code 中免费使用 Gemini 2.5 Pro API
  • JDK9+ Method.class.getDeclaredFields() Method实例将不能再直接通过反射修改
  • GaussDB 数据库架构师修炼(六)-2 集群工具管理-重建备库
  • 三、Istio流量治理(二)
  • java 之 继承
  • 【0基础PS】PS工具详解--直接选择工具
  • 秋招笔记-8.6
  • 【2025CVPR-目标检测方向】FIRE:通过频率引导重建误差对扩散生成的图像进行鲁棒检测
  • 内核链表、栈区、队列
  • 微型导轨:智能家居抽屉的智能化应用
  • Kafka-exporter采集参数调整方案
  • C语言:指针(1-2)
  • 令牌桶限流算法
  • 蚊子咬人问题何时休:深度学习引领智能灭蚊新时代
  • 【C/C++】形参、实参相关内容整理
  • SpringBoot 整合Langchain4j 对接主流大模型实战详解
  • AI Infra与LLM的联系与差异
  • 《Transformer黑魔法Mask与Softmax、Attention的关系:一个-∞符号如何让AI学会“选择性失明“》
  • 【React 插件】@uiw/react-md-editor 使用教程:从基础使用到自定义扩展
  • 【自动驾驶】《Sparse4Dv3 Advancing End-to-End 3D Detection and Tracking》论文阅读笔记
  • [科普] 从单核到千核:Linux SMP 的“演化史”与工程细节
  • MySQL数据库索引及底层数据结构