Handling file uploads in Play Framework on Heroku [duplicate]
Possible Duplicate:
Store Blob in Heroku (or similar cloud services)
I realize that Heroku has a read-only file system, and have looked at SO questions about attachment_fu
and other similar Ruby gems for handling file uploads in a transitory way so that they never really hit disk (other than temp) until they get written to Amazon S3. However, I'd like to use the Play Framework (Java) for my upcoming project, and need to support uploading pictures to a gallery.
Obviou开发者_如何转开发sly I'll need to use a writable backing store like S3 or a database blob field: I'm not married to either one as long as it works for a low volume web site (several hundred requests per month). Has anyone done this with Play on Heroku? I'm new to Play Framework, and new to Heroku, so even really obvious answers would help!
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();
精彩评论