Alamofire encodes image in which format?
Asked Answered
S

1

0

I am using alamofire to send Image to server with multipart.

multipartFormData.append(UIImageJPEGRepresentation(self.imageDet[0].image!,0.5)!, withName: "filestream", mimeType: "image/jpeg")

I have the image in byte format from server side.

Here is an example of the bytes I receive at the server side

    ����JFIFHH��XExifMM*�i&�������8Photoshop 3.08BIM8BIM%��ُ��  ���B~����"��    
���}!1AQa"q2���#B��R��$3br� 
%&'()*456789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz���������������������������������������������������������������������������    
���w!1AQaq"2�B����  #3R�br�
$4�%�&'()*56789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz��������������������������������������������������������������������������C

How can I convert the following data back to image?

Selfpossession answered 12/3, 2018 at 14:31 Comment(5)
Hint: You are explicitly converting the image to a JPG and sending that data.Tarragona
@Tarragona I know I am sending it converted into JPEG representation as the code says. But I want to know, which encoder does alamofire uses to convert the image. i.e in utf8, base64 or any other encoded. I would update the question if you think I asked wrong! I am getting some data at server side, Which I dont know how to read and convert back to image.Selfpossession
@Tarragona here I am thinking that alamofire takes .jpeg file by the JPEGRepresentation and also uses an encoder to convert the image into Data. And then it sends to Server. Did I get the concept wrong?Selfpossession
@Tarragona I just opened the image in textEdit and found its different from the bytes I receive at server side with alamofire. Is it normal, or something is going wrong?Selfpossession
@Tarragona updated question!Selfpossession
T
0

The images are encoded in JPEG and converted in binary form (Data or NSData) when you write UIImageJPEGRepresentation(...). Then this binary data is sent to the server.

Tempting answered 12/3, 2018 at 14:37 Comment(7)
How can I check the binary data is proper representation of the image I am sending. I want to cross check if I am sending the correct Image. What if I send a png format picture. Will it form an issue?Selfpossession
To check the image you can download it after you sent it and then show it in an imageView. Yes you can send a png image, convert UIImageJPEGRepresentation to UIImagePNGRepresentation and image/jpeg to image/pngTempting
I have the image in bytes form on server side, how can I convert that bytes to image? I tried copying that to text file and rename to .jpeg/.png but still the image is not generated.Selfpossession
Sorry but I can't help you with this. It's a question related to the server and not iOS/Swift or Alamofire.Tempting
its related to iOS/swift and alamofire! I just want to know the image received at server side is same as sent. And any encoding like utf8 or base64 or something like this is done by alamofire. (Main concern is crosschecking the image received is what I sent)Selfpossession
You are not giving Alamofire the jpeg file but the binary representation of the image encoded in jpeg as binary data. You are encoding the file, not Alamofire.Tempting
I think its bytes representation of Image. Binary representation will be 1 and 0. I am getting mixed characters on server side. You almost solved my first doubt. Now I just want to know how can i cross check the image I am receiving is the one I sent at server side.Selfpossession

© 2022 - 2024 — McMap. All rights reserved.