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.

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

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!