【问题标题】:Cloudfoundry: Images stored in database not displaying when app is running on cloudfoundyCloudfoundry:当应用程序在cloudfoundy上运行时,存储在数据库中的图像不显示
【发布时间】:2013-01-07 09:02:43
【问题描述】:

我有一个简单的 Grails 应用程序,它在部署到本地 Tomcat 服务器时运行良好。但是,当我部署到 Cloudfoundry 时,保存到数据库的图像没有显示。谷歌搜索解决方案只发现在 Cloudfoundry 上您不能(或不应该)使用本地文件系统来存储图像文件,但我正在使用数据库并写入控制器中的主存储器(输出流)。任何人都可以帮忙。

下面是部分代码:

//图片域类

class Picture {
    byte[] image
    String mimeType
    String name
    static belongsTo = ...

    static constraints = {
        name(maxSize:20, )
        image(maxSize:3145728)
        ....
    }
    String toString(){
        ...
    }
}


//Picture controller
def image = {

    def picture = Picture.get(params.id)

    if(!picture || !picture.image){
        ...
    }
    else{
        response.setContentType(picture.mimeType)
        response.setContentLength(picture.image.size())
        OutputStream out = response.getOutputStream();
        out.write(picture.image);
        out.flush();
        out.close();
    }
}

//在我的gsp中

谢谢。

【问题讨论】:

  • 看起来不错。你看过日志 (vmc logs yourappname) 你到底得到了什么?你有404吗?是否设置了内容长度和 MIME 类型?另外,您可以尝试使用隧道功能 (docs.cloudfoundry.com/tools/vmc/caldecott.html) 来确保图像的字节实际上在数据库中吗?
  • 感谢@ebottard 提供有关 caldecott 隧道的信息。我设法安装并运行以下查询以获得显示的结果: => select mime_type,length(image) from picture;哑剧类型 |长度 ------------+-------- 图片/jpeg | 41725 图像/JPEG | 27280 图像/JPEG | 68049 图片/jpeg | 108037(4行)
  • 当我从 grails cloudfoundry 插件运行 cf-logs 时,日志中没有错误。到目前为止唯一的日志来自 KickstartFilters.groovy: picture.list: [action:list, controller:picture] picture.image: [id:9074, action:image, controller:picture] picture.image: [id:9075,动作:图像,控制器:图片] 图片.图像:[id:9073,动作:图像,控制器:图片] 图片.图像:[id:9081,动作:图像,控制器:图片]
  • 好的。那么下一步:你得到什么http响应:404? 200?你的代码应该设置的标题怎么样,你看到它们了吗?解决这种情况的一个很好的选择是使用 Micro Cloud Foundry(docs.cloudfoundry.com/infrastructure/overview.html,查看第二个项目符号):您可以将调试器附加到它。
  • 问题消失了。我将数据库服务从 PostgreSql 切换到 mysql。似乎图像没有正确保存。

标签: grails cloud-foundry


【解决方案1】:

您的查询似乎有问题。你为什么不把你的数据库从 postgreSql 更改为 MySQL,看看问题是否仍然存在。我不认为这里的问题在于 RDBMS 服务。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-09-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多