dongzao3923 2018-11-02 16:48
浏览 72
已采纳

Symfony 4 - 上传文件的端点

I've developped an simple FileUploader Service based on the Symfony documentation found here: https://symfony.com/doc/current/controller/upload_file.html

My app is just a simple API called inside a Ionic Mobile App.

What I want to know is what is the best practices to give access to my uploaded images.

For exemple, I have an Sport entity App\Entity\Sport that stores an image: When i request GET /api/sports/ I want to send as response the full url to the image so it can be displayed inside the mobile app (e.g. http://symfony/api/public/uploads/sports/XXXXX.jpg)

Maybe I'm overcomplicating the issue but do I need to make an GET /public/uploads/sports/{id} as an endpoint to get my pictures ? because if possible i would like to have the pictures instantly available after the GET /api/sports and not having to query another time for the picture aswell

  • 写回答

1条回答 默认 最新

  • dongsutao8921 2018-11-02 16:54
    关注

    Why not just simply add the URL into a field of the JSON response object, where you can access the the picture directly? IMHO there is nothing wrong with that.

    I find https://github.com/WhiteHouse/api-standards a good reference to start with if it comes to these kind of decisions.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 file converter 转换格式失败 报错 Error marking filters as finished,如何解决?
  • ¥15 ubuntu系统下挂载磁盘上执行./提示权限不够
  • ¥15 Arcgis相交分析无法绘制一个或多个图形
  • ¥15 关于#r语言#的问题:差异分析前数据准备,报错Error in data[, sampleName1] : subscript out of bounds请问怎么解决呀以下是全部代码:
  • ¥15 seatunnel-web使用SQL组件时候后台报错,无法找到表格
  • ¥15 fpga自动售货机数码管(相关搜索:数字时钟)
  • ¥15 用前端向数据库插入数据,通过debug发现数据能走到后端,但是放行之后就会提示错误
  • ¥30 3天&7天&&15天&销量如何统计同一行
  • ¥30 帮我写一段可以读取LD2450数据并计算距离的Arduino代码
  • ¥15 飞机曲面部件如机翼,壁板等具体的孔位模型