react-native 上传文件到 PicGo

之前介绍过上传文件到Supabase,现在介绍下上传文件到PicGo

https://cctv3.net/static/20241211/react-native-upload-to-supabase.html

Snipaste 2024 12 13 09 39 58

注意上传的时候,也要Base64

完整文档参考:https://v4-docs.chevereto.com/developer/api/api-v1.html#key

假设你的相册链接是,https://www.picgo.net/album/bookkeeping-mobile.SHPRj,那么他的`id`是`SHPRj`

// 上传图片
const uploadImageToPicGo = async () => {
if (!image) {
Alert.alert("Error", "Please select an image first!");
return;
}

setUploading(true);
const base64 = await FileSystem.readAsStringAsync(image, {
encoding: "base64",
});
let instance = axios.create({
baseURL: "https://www.picgo.net",
headers: {
"X-API-Key": "******",
},
});
let formData = new FormData();
formData.append("source", base64);
formData.append("album_id", "******");
let result = await instance.post("/api/1/upload", formData);
setUploading(false);
console.log("result: ", result);
};
作者

陈桥驿站

发布于

2024-12-13

更新于

2025-01-15

许可协议

评论