react-native - React Native:更好的用户体验,从应用程序将图像保存在云中
问题描述
我的 React Native 0.62.2 应用程序需要将用户上传的图像文件保存到云端。由于上传图像需要时间,如果应用程序停止等待上传并保存到云完成,用户体验可能会很糟糕。应用程序是否应该将发布请求和数据发送到云端并继续下一步?这是应用程序中的代码:
const clickSave = async (art_obj) => {
try {
//save artwork to backend nodejs server
let img_array=[], oneImg = {};
imgs.forEach(ele => { //<<==art_obj may have many images stored in imgs
oneImg.fileName = helper.genRandomstring(8)+"_"+ele.fileName;
oneImg.path = ele.path; //local path started with file:///....
oneImg.width = ele.width;
oneImg.height = ele.height;
oneImg.size_kb = Math.ceil(ele.size/1024);
oneImg.set("image_data", ele.image_data);
img_array.push(oneImg);
});
art_obj.img_array = [...img_array]; //<<===img_array will be sent to cloud data storage (such as aws S3) and save in cloud
art_obj = JSON.stringify(art_obj);
//assemble images
let url = `${GLOBAL.BASE_URL}/api/artworks/new`;
await helper.getAPI(url, _result, "POST", art_obj); //saving art object to the backend server.
//save image to cloud storage
//shall the app just save without await so the app will not be halted and wait?
//send image array to cloud storage to save
} catch(err) {
console.log(err);
return false;
};
};
解决方案
推荐阅读
- java - Android Studio 初学者;
- python - 熊猫如何用 int64 空标记 -999999 替换
没有铸造浮动? - python - 将 mongodb 集合名称作为变量不起作用
- php - 如何防止在 Symfony 中延迟加载易受攻击的实体
- sql - 如何限制oracle表的记录有限
- google-app-engine - 部署 gcloud 应用引擎时的权限
- docker - 在 Dockerfile 中恢复 SQL Server DB.bak
- r - 基于无序的三列聚合一个数据框
- unix - MacOS 如何同时利用 APFS 和本机 UNIX (Darwin) 文件系统?
- python - 通过在 mainloop 中运行的其他脚本更新 tkinter 画布图像