在laravel控制器中:
此函数用于上传带有图像的数据:
public function addTrademark(Request $request){
$Trademark = Trademark::where('name',$request->name)->first();
if($Trademark!=null)
{
return response()->json(['message' => 'trademark already Exists']);
}
if($request->hasFile('image')){// select request image
$filename=rand(10000,1000000).$request->image->getClientOriginalName();// add rando to image name
$request->image->storeAs('images',$filename,'public'); // stor image in server file public/images
//Storage::disk('public')->put($path .'/'. $filename, base64_decode($image));
//Storage::disk($path)->put($filename, base64_decode($image));
$trademark=Trademark::create([
'name'=>$request->name,
'image'=>$filename,
'cretificate'=>$request->cretificate,
'description'=>$request->description,
'trader_id'=>$request->trader_id,
'added_at'=>$request->added_at,
'Expired_at'=>$request->expired_at,
'is_active'=>1]);
return response()->json(['message' => 'success']);
}
else{
return response()->json(['message' => 'image is empty']);
}
api json
-----------
{
"data": {
"current_page": 1,
"data": [
{
"id": 37,
"name": "jjjhhhhg",
"phone": "778405470",
"email": "kalid123@gmail.com",
"address": "حدة",
"nationality": "يمني",
"created_at": "2023-03-12T06:35:12.000000Z",
"updated_at": "2023-03-12T06:35:12.000000Z",
"image": "404782image_picker1739157224851247651.jpg",
"cretificate": "https://jjhfss.com",
"description": "errrrttt",
"trader_id": 1,
"added_at": "2023-03-12",
"Expired_at": "2024-03-12",
"is_active": 1,
"trader_name": "خالد جلب"
},]}}
和flutter中的此错误:
HTTP异常:无效的状态代码:404,统一资源标识符= http://10.0.2.2:8000/storage/images//404782image_picker1739157224851247651.jpg
flutter中图像的此根:
const String linkimageRoot =“http://10.0.2.2:8000/storage/images/“;
和此小部件在屏幕中显示图像:
ClipOval(
child: CachedNetworkImage(
height: 30,
width: 30,
imageUrl:
"$linkimageRoot/${controller.data[i]['image']}",
placeholder: (context,
url) =>
const Center(
child:
CircularProgressIndicator()),
errorWidget:
(context, url, error) =>
Icon(Icons.error),
),
),
1条答案
按热度按时间zkure5ic1#
图片url中images段后有//
http://10.0.2.2:8000/storage/images//404782image_picker1739157224851247651.jpg
尝试删除一个:
或者: