简体   繁体   English

从数据库中带有 imageurl 的文件夹中获取图像,并在我的浏览器中用 golang 中的 echo 显示

[英]get image from folder with imageurl in database and show that in my browser with echo in golang

I get my data from database and they show in browser or software like postman the same as this我从数据库中获取数据,它们显示在浏览器或软件中,如 postman 与此相同

/ 20221125143847
// http://localhost:3000/api/v1/datesmain/read

{

"alldates": [
{
  "ID": 1,
  "CreatedAt": "2022-11-25T00:00:00Z",
  "UpdatedAt": "2022-11-25T00:00:00Z",
  "DeletedAt": null,
  "volume": "20",
  "image_url": "/assets/images/IMG_3429.jpg\n",
  "average_weight": 7.5,
  "dates_type_id": 1,
  "wight_type_id": 1
},
{
  "ID": 2,
  "CreatedAt": "2022-11-25T00:00:00Z",
  "UpdatedAt": "2022-11-25T00:00:00Z",
  "DeletedAt": null,
  "volume": "15",
  "image_url": "/assets/images/IMG_3436.jpg\n",
  "average_weight": 7.5,
  "dates_type_id": 1,
  "wight_type_id": 1
}
  ]
}

as you se image url is currect and all images are in filder in root of project with the name of "assets" as I undrestand its possible show my image by this URL如您所见,图像 url 是正确的,所有图像都在项目根目录中的文件夹中,名称为“资产”,因为我不理解它可能通过这个 URL 显示我的图像

http://localhost:3000/api/v1/datesmain/assets/images/IMG_3429.jpg http://localhost:3000/api/v1/datesmain/assets/images/IMG_3429.jpg

I want to show all of them as a listview in front end with java or...我想用 java 或 ...

but when copy and past one of url in browser like this但是当像这样在浏览器中复制并过去 url 之一时

// http://localhost:3000/api/v1/datesmain/static/images/IMG_3429.jpg { "message": "Not Found" } // http://localhost:3000/api/v1/datesmain/static/images/IMG_3429.jpg { "message": "Not Found" }

How can I resolve that?我该如何解决?

and this is my tiny code这是我的小代码

func ReadAllDatesMain(e echo.Context) error {
ad, err := logic.ReadAllDatesMain()
if err != nil {
    return nil
}
return e.JSON(http.StatusOK, map[string]interface{}{
    "alldates": ad,
})

} }

You have defined route for your API but not for your files.您已经为您的 API 定义了路由,但没有为您的文件定义路由。 You need to set static route in echo.您需要在 echo 中设置static 路由 Then you can access the folder structure by URL from client like browser or postman.然后你可以从浏览器等客户端通过 URL 或 postman 访问文件夹结构。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM