OK, I found the fix. The answer was in this thread.
https://github.com/deliciousbrains/wp-amazon-s3-and-cloudfront/issues/285
I was making exactly the same error.
Solution was to change
$image[‘type’] = ‘image/jpg’;
to
$image[‘type’] = ‘image/jpeg’;
In my case, I am using https://github.com/scottgonzalez/node-wordpress
and the following code upload images to S3. Previously I was specifying type: ‘image/jpg’ which caused images to upload to the host instead of S3.
const fsp = require('fs-promise')
fsp.readFile(path).then(
(data) => {
const file = {
name: path.slice(path.lastIndexOf('/') + 1),
type: 'image/jpeg',
bits: data,
overwrite: true
}
console.log(<code>Upload ${file.name} via XML-RPC</code>)
this._wp.uploadFile(file, (err, res) => {
if (err) {
console.log(err)
reject(err)
} else {
console.log(res)
resolve(res)
}
})
},
(err) => {
console.log(err)
}
)