[英]Android studio Display image from Laravel API
I am using Retrofit API to access my Laravel site data.我正在使用 Retrofit API 来访问我的 Laravel 站点数据。 I am not able to display images in my android app.我无法在我的 android 应用程序中显示图像。
Here is my Laravel code to save images in my Laravel site.这是我的 Laravel 代码,用于将图像保存在我的 Laravel 站点中。
$path = 'images/no-thumbnail.jpeg';
if($request->has('thumbnail')){
$extension = ".".$request->thumbnail->getClientOriginalExtension();
$name = basename($request->thumbnail->getClientOriginalName(), $extension).time();
$name = $name.$extension;
$path = $request->thumbnail->storeAs('images', $name, 'public');
}
Here is the API response for the Products tabel.这是 Products 表的 API 响应。
[{"id":1,"user_id":"1","title":"White T shirt","description":"White T shirt small size","categorie":"1","price":"50","discount_price":"0","thumbnail":"images\/81vzc0ciKwL._AC_UX679_1619280040.jpg","slug":"white-t-shirt","options":null,"featured":"0","status":"0","created_at":"2021-04-24T16:00:40.000000Z","updated_at":"2021-04-24T16:00:40.000000Z","deleted_at":null}]
The response of the image is this "thumbnail":"images/81vzc0ciKwL._AC_UX679_1619280040.jpg"图像的响应是这个“缩略图”:“images/81vzc0ciKwL._AC_UX679_1619280040.jpg”
For my android app, I am using Picasso here is the code.对于我的 android 应用程序,我使用的是 Picasso,这里是代码。
Picasso.get().load(shopesModel.getThumbnail()).into(holder.shopImg);
But still, I am not getting images in my android app.但是,我仍然没有在我的 android 应用程序中获得图像。 I am getting other fields of the product table.我正在获取产品表的其他字段。
Here is the screenshot of the app这是应用程序的屏幕截图
Where should I change my code.我应该在哪里更改我的代码。 Laraval or change my app code so that I can get images from Laravel. Laraval 或更改我的应用程序代码,以便我可以从 Laravel 获取图像。
Since your json response doesn't have qualified url in thumbnail由于您的 json 响应在缩略图中没有合格的 url
"thumbnail":"images\/81vzc0ciKwL._AC_UX679_1619280040.jpg"
There two ways you can fix 1.best solution is to send full url image path from server side 2.hardcoding base url in your android and append to Picasso There two ways you can fix 1.best solution is to send full url image path from server side 2.hardcoding base url in your android and append to Picasso
"thumbnail":"https://urdomain/storage/images/81vzc0ciKwL._AC_UX679_1619280040.jpg"
or或者
String baseUrl="https://urdomain/storage/";
Picasso.get().load(baseUrl+shopesModel.getThumbnail()).into(holder.shopImg);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.