I have to implement a server that lets some users upload possibly huge files (multi gigabytes worth of files) to S3 (they do not know it is S3 though). I have already implemented something similar in Python and a basic implementation using Play framework.
Right now my uploading function looks like this:
public Result uploadFile() {
List<Http.MultipartFormData.FilePart> files = request().body().asMultipartFormData().getFiles();
if (CollectionUtils.isNotEmpty(files)) {
Bucket bucket = MY_BUCKET;
UUID timeuuid;
Promise<UploadResult> promise;
ObjectNode responseMessage = Json.newObject();
for (Http.MultipartFormData.FilePart file : files) {
timeuuid = TimeUUID.now();
promise = Promise.promise(new UploadFunction(timeuuid, bucket, file.getFile(), obtainS3Connection()));
responseMessage.set(file.getFilename(), TextNode.valueOf(timeuuid.toString()));
}
return accepted(responseMessage);
} else {
return badRequest("files empty");
}
}
I am not worried about the upload code itself and actually I already have implemented it many times. What I am worried about is making it so that Play! does not save Files to disk and that the files sent only "pass through" my server without being written to disk (even as temp files). I have some processing involved and sometime "Client side" encryption of some content by I can do that as a Stream.
I was wondering if Play already does that? Or how would I achieve that?
What I am assuming Play (and Django in my previous version of this service) does is:
Upload --> Play MyProcessing -------> S3
\ /
\ /
Disk
What I would like it to do :
Upload --> Play --> MyProcessing -------> S3
The reason I want to do this is that I want the potential to deploy my service on instances with very small disks and I also want the guarantee that nobody can find the unencrypted file (if I choose to encrypt it) once uploaded.
UPDATE: I am not giving up ... just yet.
I have found a few possible solution that unfortunately use Scala. They all revolve around the same theme as this discussion: Play 2.x : Reactive file upload with Iteratees
I was wondering if this would be possible using Java (I am the only one in my company that knows Scala so I cannot roll out something for which I would be the only person able to do maintenance on it ... because sometimes I wish to take breaks or go on other projects).