I am using python on the server-side
So you can use jpegtran-cffi Python package that provides the ability to perform EXIF auto-transform:
# jpegtran can transform the image automatically according to the EXIF
# orientation tag
photo = JPEGImage(blob=requests.get("http://example.com/photo.jpg").content)
print photo.exif_orientation # "6" (= 270°)
print photo.width, photo.height # "4320 3240"
corrected = photo.exif_autotransform()
print corrected.exif_orientation # "1" (= "normal")
print corrected.width, corrected.height # "3240 4320"
Note: extracted from the README.
As an alternative there is also a convenient command-line tool called jhead that you can use for the same purpose:
# Remove EXIF orientation
# i.e. rotate the image accordingly and reset the orientation
# flag to 1 (default, i.e. origin = TopLeft)
# WARNING: the image file is overwritten!
# NOTE: it also works with a wildcard: jhead -autorot *.jpg
jhead -autorot myimage.jpg