Search code examples
amazon-web-servicesamazon-s3amazon-cloudfront

Is there a way to stream files from aws s3 but using multiple mp3 files as a single stream?


Right now I have a setup where multiple mp3 files exist in an AWS s3 bucket. The bucket is made public and I am able to download individual mp3 files from the URL created by aws s3.

I want to make a radio streaming service that will traverse through those mp3 files in a continuous fashion. is there any way maybe using cloudfront to do this?

ex: song1.mp3 song2.mp3, song3.mp3

These 3 will play in sequence with a single call.


Solution

  • I realized adding an encoding type when uploading files via the extra args parameter allows the file to be streamed rather than downloaded.

    import mimetypes
    
    # Guess file type
    mimetype, _ = mimetypes.guess_type(fname)
    if mimetype is None:
        raise Exception("Failed to guess mimetype")
    else:
        print("\nMimetype: ", mimetype)
    
     s3.upload_file(fname, S3_TO_BUCKET_NAME, key,
        Callback = ProgressPercentage(fname),
        ExtraArgs={'ContentType': mimetype})