duaiwo9093 2013-04-12 18:32
浏览 38


I'm fairly new with CakePHP and images so bear with me. You can assume I'm using the latest version.

I'm trying to build an Android application which can display images retrieved from the server.

Suppose I have an image in the assets folder called football.jpg. How would I store this in the database and then how would I output this to the Android application? Do I send only the link or do I send the whole image over? If it is just the link, does this mean I would have to reconnect to the server with the link and then get the image? Sorry if this doesn't make sense. Still trying to get my head around it.

  • 写回答

1条回答 默认 最新

  • dongxu3029 2013-04-13 13:51

    Just a word of caution, it's probably better to store the file on the server's file system and store the path to the file in the database. The reason behind this is that BLOBs are stored in a different area on the file system to all your other typical data and in terms of retrieval, its not a great deal faster.

    Here's a link to what I mean: Store pictures as files or in the database for a web app?

    With regards to returning it to your Android app, you can send files in the response object (http://book.cakephp.org/2.0/en/controllers/request-response.html#cake-response-file):

    public function sendFile($id) {
        $file = $this->Attachment->getFile($id);
        //Return reponse object to prevent controller from trying to render a view
        return $this->response;

    This should give you finer control over what files are returned to your client.

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



  • ¥20 找驱动QTR2774-SU-IBM版本驱动
  • ¥15 NeRF的代码复现以及人工智能入门
  • ¥15 centos如何做一个可以让ikuai连接的openvpn
  • ¥15 Protege 中的Entities下面的界面删除了如何复原
  • ¥15 scrapy爬虫求帮
  • ¥15 imageEnView绘图问题
  • ¥15 关于#python#的问题:您好可以加您一下联系方式吗,在复现的时候确实有点问题难以解决
  • ¥15 联想电脑重装系统时无法发现硬盘
  • ¥15 MATLAB与UR10e实体机械臂建立通讯
  • ¥15 c++题需要快一点不用opencv