S3 file is corrupted when using putObject

Viewed 524

I'm trying to put and object into my s3 bucket using this data returned from my Sagemaker endpoint.

<Buffer 50 4b 03 04 14 00 00 00 08 00 6c 83 85 50 2c 2e dd 02 9e 61 93 00 fa 7f a1 00 32 00 00 00 6f 75 74 70 75 74 2f 61 75 64 69 6f 5f 66 69 6c 65 5f 31 35 ... > }

The put request to s3 works perfectly. The file size is as expected, 18mb. However, when I try to play the mp3 link inside the browser, or download the file to play, it says the file it gives me this error:

This file isn't playable. That might be because the file type is unsupported, the file extension is incorrect, or the file is corrupt.

Here is my putObject function:

var params = {
    Bucket : 'musicbucket-audio-uploads',
    Key : 'test.wav',
    Body : data.Body, //This is the Buffer Data
    ContentType: 'audio/wav'
};
s3.putObject(params, function(err, data) {
     if (err) console.log('PutObject Error: ' + err); 
     else     console.log(data);          
});

I think I'm doing a step incorrectly in my params for putObject, but unsure what it is. Could someone please help me spot my mistake?

1 Answers

The initial bytes of your file don't match the WAV fie format (RIFF) and don't look like an MP3. It must be some other file format. I would check SageMaker model docs or a specification - what does it say about the format of the returned buffer?

Update: seems that it's a ZIP file. Note that 50 4b hex bytes are PK (for Phil Katz, the creator of the original ZIP compression format).

Related