簡體   English   中英

Android studio 顯示圖像來自 Laravel API

[英]Android studio Display image from Laravel API

我正在使用 Retrofit API 來訪問我的 Laravel 站點數據。 我無法在我的 android 應用程序中顯示圖像。

這是我的 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');
    }

這是 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}]

圖像的響應是這個“縮略圖”:“images/81vzc0ciKwL._AC_UX679_1619280040.jpg”

對於我的 android 應用程序,我使用的是 Picasso,這里是代碼。

Picasso.get().load(shopesModel.getThumbnail()).into(holder.shopImg);

但是,我仍然沒有在我的 android 應用程序中獲得圖像。 我正在獲取產品表的其他字段。

這是應用程序的屏幕截圖

在此處輸入圖像描述

我應該在哪里更改我的代碼。 Laraval 或更改我的應用程序代碼,以便我可以從 Laravel 獲取圖像。

由於您的 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

"thumbnail":"https://urdomain/storage/images/81vzc0ciKwL._AC_UX679_1619280040.jpg" 

或者

String baseUrl="https://urdomain/storage/";

Picasso.get().load(baseUrl+shopesModel.getThumbnail()).into(holder.shopImg);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM