要显示图像,在离子页面视图中使用Laravel从其余API响应。
与邮递员一起测试时,代码可以正常工作,但在离子中会出现错误:
SyntaxError:意外令牌-JSON中的JSON.parse位置0 ...
HTTP状态为200
使用JWT
后端:
g++ main.o Aleatori.o -o Aleatori.exe
./Aleatori
Benvingut al Brain Training Game! Si us plau, selecciona una dificultat:
1 - Facil
2 - Mig
3 - Dificil
服务或提供者中的频率终止
public function maPhotoApi(Request $request){
$user = auth()->user();
$residentModel = new Resident();
$resident = $residentModel->getResidentByIdUser($user->id);
if (is_dir(base_path('resources/resident/' . $resident->id_resident . '/')) && file_exists(base_path('resources/resident/' . $resident->id_resident . '/') . 'photo.jpg')) {
$img = file_get_contents(base_path('resources/resident/' . $resident->id_resident . '/') . 'photo.jpg');
return response($img)->header('Content-type', 'image/jpeg');
} else {
$img = file_get_contents(base_path('resources/resident/profil.png'));
return response($img)->header('Content-type', 'image/jpeg');
}
}
组件:
maPhoto(){
let httpOpt = {
headers: new HttpHeaders({
'Access-Control-Allow-Origin': '*',
'Authorization' : 'Bearer '+localStorage.getItem('token'),
'Content-type': 'image/jpeg',
})
};
return this.http.get(this.url + "maPhoto", httpOpt);
}