简体   繁体   English

Android studio 显示图像来自 Laravel API

[英]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.

相关问题 在android studio中显示来自网址的可滚动图像 - Display a scrollable image from a url in android studio 如何在 Android Studio 的 Recyclerview 中显示取自 API 的 JPG 图像? - How can I display a JPG image, taken from an API, in a Recyclerview in Android Studio? 从 android 上传图像文件到 laravel api - Upload image file to laravel api from android 无法显示移动存储中的所选图像(Android Studio) - Cannot display the selected image from mobile storage (Android Studio) 将图像文件从Android设备上传到Laravel API - Upload image file from Android Device to Laravel API 来自 Google Drive Android Studio API 的图像被旋转 - Image from Google Drive Android Studio API gets rotated 显示来自 api 数据 android studio java 的图像 - Show image from api data android studio java 从相机获取图像或从图库上传并在 ImageView (Android Studio) 中显示后,保存图像为 SharedPreferences - Save image is SharedPreferences after Image is get from camera or upload from gallery and display at ImageView (Android Studio) Laravel 4 REST API在Android Studio中使用Retrofit - Laravel 4 REST API using Retrofit in Android Studio 如何在 Android Studio 中的图像上显示矩形 - How to display a rectangle over an Image in Android Studio
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM