Reactjs React native expo FileSystem.downloadAsync损坏的映像
我们有RN应用程序和服务器来存储图像 尝试根据用户从服务器下载束图像,并在RN应用程序中显示它们 有时图像会被破坏,或者根本不显示,所以我必须重新加载应用程序才能工作(这在很多时候都不会工作),或者清除存储并一次又一次地下载图像 这是要下载的功能之一:Reactjs React native expo FileSystem.downloadAsync损坏的映像,reactjs,react-native,filesystems,expo,Reactjs,React Native,Filesystems,Expo,我们有RN应用程序和服务器来存储图像 尝试根据用户从服务器下载束图像,并在RN应用程序中显示它们 有时图像会被破坏,或者根本不显示,所以我必须重新加载应用程序才能工作(这在很多时候都不会工作),或者清除存储并一次又一次地下载图像 这是要下载的功能之一: downloadItemsImgs = async() => { const {items, u_clname} = this.state for (let [key, value] of Object.entries(items))
downloadItemsImgs = async() => {
const {items, u_clname} = this.state
for (let [key, value] of Object.entries(items)) {
let imgPath = FileSystem.documentDirectory + value.item_img;
let imgName = value.item_img;
await FileSystem.getInfoAsync(imgPath).then(file => {
if (file.exists === false) {
try {
FileSystem.downloadAsync(
'https://servernamehere.com/uploads/' + u_clname +'/' + imgName, imgPath
)
}
catch (error) {
alert(error);
}
}
})
}
}
这是out函数:
outPutItems = (id) => {
let fileSystemPath = FileSystem.documentDirectory;
let output = [];
const {items} = this.state
for (let [key, value] of Object.entries(items)) {
if (value.group_id === id) {
output.push(
<Card
style={styles.itemCard}
key={value.item_id}
>
<CardItem
cardBody
button
activeOpacity={0.5}
onPress={() => {
this.goOneItem(value.item_id, value.item_name, value.group_id);
}}
>
<ImageBackground
source={{uri: `${fileSystemPath}${value.item_img}`}}
style={{height: 250, width: null, flex: 1}}
>
<View style={[styles.itemTextContainer, {flexDirection: "column"}]}>
<View style={[styles.itemPriceText]}>
<Text style={styles.itemText}>{value.item_name}</Text>
</View>
<View style={{ flexDirection: "row", justifyContent: "space-between", alignItems: "center", width: "100%", padding: 4,}}>
<Text style={styles.priceText}>{value.item_price} AED</Text>
</View>
</View>
</ImageBackground>
</CardItem>
</Card>
)
}
}
return output;
}
outPutItems=(id)=>{
让filesystems=FileSystem.documentDirectory;
让输出=[];
const{items}=this.state
for(让对象的[key,value]项(项)){
if(value.group_id==id){
输出推送(
{
this.goOneItem(value.item\u id、value.item\u name、value.group\u id);
}}
>
{value.item_name}
{value.item_price}AED
)
}
}
返回输出;
}
注意:我尝试在几个网络中下载(我认为这可能是一个与网络相关的问题),但仍然是同一个问题
我花了很长时间才弄清楚问题出在哪里,是下载函数还是输出