robby987
robby987

Reputation: 827

Amazon AWS boto S3 Changing file contents

enter image description hereTrying to upload a mp4 file to an Amazon S3 server, it uploads. When downloading it's exactly the same size but bytes 42, 43, 44 changes.

Looking up that's mdat. http://www.file-recovery.com/mp4-signature-format.htm

I tried changing mime types to various ones and also even changed extension to exe. No luck..

When trying to playback the video it does not work.

I'm using the boto python framework to do this.

Any ideas?

 # Uploads a file to a bucket
def upload_file_to_bucket(self, file_path_on_disk, file_name_in_bucket, bucket_name):
    self.remove_file_from_bucket(file_name_in_bucket, bucket_name)
    if os.path.exists(file_path_on_disk):
        print "Uploading " + file_path_on_disk + " to " + file_name_in_bucket + " in bucket " + bucket_name
        bucket = self.get_connection().get_bucket(bucket_name)
        k = bucket.new_key(file_name_in_bucket)
        k.set_contents_from_filename(file_path_on_disk, headers = {'Content-Type' : 'application/octet-stream', 'Body' : 'data'}) # {'Content-Disposition': 'attachment', 'Content-Type' : 'video/mp4'}) headers = {'Content-Type' : 'application/octet-stream'}
        k.set_acl('public-read')
        print "Uploaded file to amazon server " + bucket_name 
    else:
        print "File does not exist so cannot upload " + file_path_on_disk

Edit: Looking further. seems there is a lot more corruption than that. Dodgy Load balancer?

Is it possible there a way to ensure the file is uploaded correctly? At the moment, it's always wrong.

EDIT:

This was due to the file not being fully written before being uploaded if anyone encounters this.

Upvotes: 0

Views: 1832

Answers (1)

Frederic Henri
Frederic Henri

Reputation: 53733

The right content type is video/mp4 you can set it like this from both

data = open('file.mp4', 'rb')
bucket.put_object(Key='file.mp4', Body=data, ContentType='video/mp4')

make sure the type is set correctly after upload in the s3, navigate to your file and check the properties / Metadata. Note that video/mp4 is not in the drop down list of available content type from AWS but you can force it by writing the content you want

Upvotes: 1

Related Questions