i had uploaded my laravel project on hosting server, the images was stored in laravel/public folder then the generated url saved in my database like as: public/image.jpg, how can I retrieve the images in flutter by using online website url??
in flutter application : main_url="http://mydomain.byethost7.com/api/";
FutureBuilder(
future: downloadImage(url),
builder: (BuildContext context, AsyncSnapshot snapshot) {
if (snapshot.connectionState == ConnectionState.done &&
snapshot.hasData) {
return Container(
width: w,
height: h,
child: Image.network(snapshot.data.toString(),fit: BoxFit.cover));
}
return Container();
}
)
Future<String> downloadImage(String url)async
{
return await main_api_url + "getimage/$url";
}
in laravel api.php file is:
Route::get('getimage/{url}','App\Http\Controllers\Api\ImageController','get_image']);
in ImageController i have this function to return image as file:
public function get_image($url)
{
ob_end_clean();
return response()->file(public_path('storage/public/'.$url));
}
in laravel my ImageController class:
class ImageController extends Controller
{
public function save_images(Request $req)
{
if($req->hasFile($op['images']))
{
$images=$req->file($op['images']);
foreach ($images as $image)
{
$path=$image->store('public');
$img=new Image();
$img->url=$path;
$img->product_id=$product_id;
$img->title="";
$img->save();
}
}
}
}
in database images table: enter image description here
but in flutter i got this error:
Exception caught by image resource service ================================================
The following _Exception was thrown resolving an image codec:
Exception: Invalid image data
When the exception was thrown, this was the stack:
#0 _futurize (dart:ui/painting.dart:6637:5)
#1 ImageDescriptor.encoded (dart:ui/painting.dart:6494:12)
#2 instantiateImageCodecWithSize (dart:ui/painting.dart:2291:60)
#3 PaintingBinding.instantiateImageCodecWithSize (package:flutter/src/painting/binding.dart:182:15)
#4 NetworkImage._loadAsync (package:flutter/src/painting/_network_image_io.dart:153:22)
<asynchronous suspension>
Image provider: NetworkImage("http://murhafyildiz.byethost7.com/api/getimage/7zTKC23PVI5WTmGrbAIjnyQMFRMZEYUdzL9csuq9.png", scale: 1.0)
Image key: NetworkImage("http://murhafyildiz.byethost7.com/api/getimage/7zTKC23PVI5WTmGrbAIjnyQMFRMZEYUdzL9csuq9.png", scale: 1.0)
====================================================================================================