在 Heroku(或类似的云服务)中存储 Blob [英] Store Blob in Heroku (or similar cloud services)

查看:15
本文介绍了在 Heroku(或类似的云服务)中存储 Blob的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 Heroku 中部署一个应用程序来试用他们的新 Play!框架支持.对于我在网站上读到的内容(我必须承认我还没有尝试过),他们不提供任何文件系统.这意味着(可能)Play 中用于存储文件的 Blob 字段将无法正常工作.

I want to deploy an app in Heroku to try their new Play! Framework support. For what I've read in the site (I gotta confess I did not try it yet) they don't provide any file system. This means that (probably) Blob fields used in Play to store files won't work properly.

有人可以:

  • 确认您是否可以在 Heroku 中使用 Play Blob?
  • 提供在 Heroku 中存储文件的最佳"替代方案?将它们存储在数据库中(他们使用 PostgreSQL)还是其他地方更好?

推荐答案

我在 github 上放了一个关于如何使用 Amazon S3 执行此操作的示例:
https://github.com/jamesward/plays3upload

I put an example of how to do this with Amazon S3 on github:
https://github.com/jamesward/plays3upload

基本上你只需要将文件发送到 S3 并将密钥保存在实体中:

Basically you just need to send the file to S3 and save the key in the entity:

AWSCredentials awsCredentials = new BasicAWSCredentials(System.getenv("AWS_ACCESS_KEY"), System.getenv("AWS_SECRET_KEY"));
AmazonS3 s3Client = new AmazonS3Client(awsCredentials);
s3Client.createBucket(BUCKET_NAME);
String s3Key = UUID.randomUUID().toString();
s3Client.putObject(BUCKET_NAME, s3Key, attachment);
Document doc = new Document(comment, s3Key, attachment.getName());
doc.save();
listUploads();

这篇关于在 Heroku(或类似的云服务)中存储 Blob的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆