2018-11-02 16:48
浏览 72

Symfony 4 - 上传文件的端点

I've developped an simple FileUploader Service based on the Symfony documentation found here:

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

图片转代码服务由CSDN问答提供 功能建议

我已根据此处的Symfony文档开发了一个简单的FileUploader服务: \ n

我的应用程序只是一个在Ionic Mobile App中调用的简单API。


例如,我有一个存储图像的Sport实体 App \ Entity \ Sport : 当我请求 GET / api / sports / 我想将完整的url作为响应发送到图像,以便它可以显示在移动应用程序中(例如 http://symfony/api/public/uploads/sports/XXXXX.jpg

也许我的问题过于复杂,但我是否需要制作 GET / public / uploads / sports / {id} 作为端点 得到我的照片? 因为如果可能的话,我想在 GET / api / sports 之后立即获得图片,而不必再查询图片的其他时间

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

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 a good reference to start with if it comes to these kind of decisions.

    打赏 评论

相关推荐 更多相似问题