首页 > 解决方案 > 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;
        };
    };

标签: react-nativeamazon-s3

解决方案


推荐阅读