Skip to content
This repository has been archived by the owner on Nov 20, 2019. It is now read-only.

Can't stream S3 video/Image while downloading #66

Open
hubino-testing2 opened this issue May 25, 2016 · 1 comment
Open

Can't stream S3 video/Image while downloading #66

hubino-testing2 opened this issue May 25, 2016 · 1 comment

Comments

@hubino-testing2
Copy link

I can't stream the S3 video/Image while downloading. I can able to read the private bucket by using my aws.accessKeyId and aws.secretKey. I have used the below way.

Code snippet:
In HTML:

<!DOCTYPE html>
<html>
    <body>
        <img width="240" height="320" src="@routes.Application.loadS3File("user.png")" />
        <video controls="controls" preload controls width="320" height="240" name="Video Name">
            <source src="@routes.Application.loadS3File("user.mov")" type='video/mp4; codecs="avc1.42E01E, mp4a.40.2"' />
        </video>
    </body>
</html>

In Controller:

**method-1:**
def loadS3File(filename: String) = Action { implicit request =>
        try {
            val bucket = S3("user")
            val result = bucket.get(filename)
            val file = Await.result(result, 60 seconds)
            val BucketFile(name, contentType, content, acl, headers) = file
            Ok.chunked(Enumerator(content)).as(contentType);
        }
        catch {
            case e: Exception =>
                BadRequest("Error: " + e.getMessage)
        }
    }

**method-2:**
def loadS3File(filename: String) = Action.async {
        val bucket = S3("user")
        bucket.get(filename).map {
            case BucketFile(name, contentType, content, acl, headers) =>
                val byteString: ByteString = ByteString.fromArray(content)
                Ok.chunked(Enumerator(byteString)).as(contentType)
        }

    }

It waits to read the whole file content from S3. But the it doesn't return video to html. If I tried to show the S3 image, it read the whole image content from S3 and return to the html successfully.
I can't stream the video/Image while downloading in progress.

@EECOLOR
Copy link
Member

EECOLOR commented May 27, 2016

The library does not support streaming out-of-the box. You might want to check out this thread on stackoverflow to get a feel of the complexity. You can also check #42

As for now I recommend you use the library to create an url directly to the file and use that with your videoplayer. This has the added benefit that the file does not need to travel through your server but goes directly from s3 to the browser of the client.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants