Я разрабатываю приложение на реагирующем языке, используя expo, и бэкэнд находится в Laravel В основном я делаю модуль Profile для загрузки фото
Разработан бэкэнд API. Вот мой бэкэнд код
public function EditProfile(Request $request){
//Creating model and input values
$profile = new ProfilePicEditModel;
$profile->user_id = Auth::id();
$profile->name = $request->name;
$profile->occupation = $request->occupation;
$profile->waystatus = $request->waystatus;
//Image Proceesing to Upload
$fileName=Auth::id().".png";
$path = $request->file('image')->move(public_path("/ShareYourMealProfilePics"),$fileName);
$photoURL= url('/ShareYourMealProfilePics/'.$fileName);
$profile->image=$photoURL;
$profile->phone = $request->phone;
$profile->save();
return response()->json($profile,200);
}
Вот моя модель
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class ProfilePicEditModel extends Model
{
protected $table="profile";
//public $timestamps=false;
protected $fillable=[
'user_id',
'name',
'occupation',
'waystatus',
'image',
'phone',
];
}
А вот код React native здесь
export default class EditProfile extends React.Component{
constructor() {
super();
this.state = {
name:'',
occupation:'',
waystatus:'',
image:'',
phone:'',
};
}
selectPicture = async () => {
await Permissions.askAsync(Permissions.CAMERA_ROLL);
const { cancelled, uri } = await ImagePicker.launchImageLibraryAsync({
aspect: 1,
allowsEditing: true,
});
if (!cancelled) this.setState({ image: uri });
};
updateProfile=async()=>{
// console.log(this.state.name,this.state.occupation,this.state.waystatus,this.state.image,this.state.phone);
fetch('http://192.168.1.7:8000/api/EditProfile',{
method:'post',
headers:{
'Authorization': `Bearer ${GLOBAL.mytoken}`,
'Content-Type':'application/json',
'Accept': 'application/json'
},
body:JSON.stringify({
"name":this.state.name,
"occupation":this.state.occupation,
"waystatus":this.state.waystatus,
"image":this.state.image,
"phone":this.state.phone
})
}).then((response)=> response.json())
.then((res)=>{
if(typeof(res.message)!="undefined"){
Alert.alert(res.message);
}
else{
Alert.alert("Success","You have succesfuly Updated Your Profile",
[
{
text: 'Continue', onPress: () => {
Actions.Profile();
}
}
],
{ cancelable: false })
}
}).catch((error)=>{
console.error(error);
});
}
render(){
const {goBack} = this.props.navigation;
return(
<SafeAreaView style={styles.container}>
<ScrollView showsVerticalScrollIndicator={true} style={{marginHorizontal:10}}>
<View style={styles.titleBar}>
<Ionicons name="ios-arrow-back" size={24} color="#52575D"
onPress={() => goBack()}
></Ionicons>
<Text style={{fontSize: 22,fontWeight:"400",justifyContent:"center",marginLeft:110}}>Edit Profile </Text>
</View>
<Text style={{marginLeft:30,fontSize:17,marginTop:25,fontWeight:"300"}}>Please Select Your Profile Pic</Text>
<TouchableOpacity
onPress={this.selectPicture}>
<FontAwesome name="camera" size={35} style={{justifyContent:"center",marginTop:17,alignSelf:"center"}}/>
</TouchableOpacity>
<Item floatingLabel style={{marginTop:10}}>
<Label style={{marginLeft:30}}>Name </Label>
<Input style={{marginLeft:10,marginRight:10}}
onChangeText={(name) => this.setState({name})}
/>
</Item>
<Item floatingLabel style={{marginTop:20}}>
<Label style={{marginLeft:30}}>Sub Name/Occupation </Label>
<Input style={{marginLeft:10,marginRight:10}}
onChangeText={(occupation) => this.setState({occupation})}
/>
</Item>
<Item floatingLabel style={{marginTop:20}}>
<Label style={{marginLeft:30}}>Status </Label>
<Input style={{marginLeft:10,marginRight:10}}
onChangeText={(waystatus) => this.setState({waystatus})}
/>
</Item>
<Item floatingLabel style={{marginTop:20}}>
<Label style={{marginLeft:30}}>Phone No.</Label>
<Input style={{marginLeft:10,marginRight:10}} keyboardType={'numeric'} returnKeyType='done'
onChangeText={(phone) => this.setState({phone})}
/>
</Item>
<Button rounded style={styles.postSeat}
onPress={()=>this.updateProfile()}>
<Text>Update</Text>
</Button>
</ScrollView>
</SafeAreaView>
)}
}
Когда я выбираю изображение и заполняю все поля и затем нажмите кнопку обновить ее
ошибка вызов функции-члена move () на null
Я не знаю, где находится ошибка, но я думаю, что ошибка из-за загрузки изображения на бэкенде, пожалуйста, дайте мне знать, ошибка в бэкенде или на собственной стороне реакции
И еще один вопрос. Мы храним только "uri" изображения ????