This code is to preserve the orientation information right?

So you also need to do that for images that don't have an embedded preview. There are two other sites that call createThumbnailAndPreview that also need to have the orientation value passed through to the callback.

Actually, don't you need to pass the orientation to createThumbnailAndPreview so that you can rotate the thumbnail correctly?  If you do that, then it can just put the orientation into the metadata object for you, and you won't need that code.