2

我正在使用 react-native-image-picker 从系统中获取图像。一旦用户选择和图像,我正在调度一个 redux 操作,它看起来像这样。

imgSrc变量包含图像 URI。我使用 split 和 pop 来获取图像名称。但是图像仍然没有从 imgSrc 复制到我新生成的路径。

export const addPlace = (title , address , imgSrc) =>{
    return async dispatch => {
        const fileName = imgSrc.split('/').pop()
        const newPath = RNFetchBlob.fs.dirs.DocumentDir + '/' + fileName

        try{
            await RNFetchBlob.fs.cp( imgSrc , newPath)
        } catch ( err){
            console.log('error')
            throw err
        }

        dispatch({
            type : ADD_PLACE ,
            placeData : {
                title : title,
                address : address,
                src : newPath
            }
        })
    }
}
4

0 回答 0