将Blob存储在Heroku(或类似的云服务) [英] Store Blob in Heroku (or similar cloud services)
本文介绍了将Blob存储在Heroku(或类似的云服务)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在 Heroku 中部署应用程序,尝试新的Play!框架支持。对于我在网站上读到的内容(我必须承认我还没有尝试过),他们没有提供任何文件系统。这意味着Play中用于存储文件的(可能)Blob字段将无法正常工作。
有人可能:
- 确认您是否可以在Heroku中使用Play Blob?
- 提供在Heroku中存储文件的最佳选择?最好是将它们存储在数据库(它们使用PostgreSQL)或其他地方? 我举了一个如何在github上使用Amazon S3完成此任务的示例:
- Confirm if you can use the Play Blob in Heroku?
- Provide the "best" alternative to store files in Heroku? Is better to store them in the database (they use PostgreSQL) or somewhere else?
https:// github .com / jamesward / plays3upload
基本上你只需要将文件发送到S3并将密钥保存在实体中:
AWSCredentials awsCredentials = new BasicAWSCredentials(System.getenv(AWS_ACCESS_KEY),System.getenv(AWS_SECRET_KEY));
AmazonS3 s3Client =新的AmazonS3Client(awsCredentials);
s3Client.createBucket(BUCKET_NAME);
String s3Key = UUID.randomUUID()。toString();
s3Client.putObject(BUCKET_NAME,s3Key,附件);
Document doc = new Document(comment,s3Key,attachment.getName());
doc.save();
listUploads();
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.
Could somebody:
解决方案
I put an example of how to do this with Amazon S3 on github:
https://github.com/jamesward/plays3upload
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();
这篇关于将Blob存储在Heroku(或类似的云服务)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文