You'll need to transform the image to correct the orientation. Fortunately, the image should include EXIF data that you can use to do that. If you like, you can do this before the image is uploaded to your server:
- Read the image's EXIF data
- Use a canvas element to transform the image as appropriate
- Export the canvas image into an image file
There's an excellent writeup, including code samples, in this blog post.