encode image to base64, get a invalid base64 string (ios using base64EncodedStringWithOptions)

后端 未结 4 761
误落风尘
误落风尘 2021-02-05 19:39

Here is my code.

  UIImage *img = [UIImage imageNamed:@\"white.jpeg\"];
  NSData *imageData = UIImagePNGRepresentation(img);
  NSString *imageString = [imageData         


        
4条回答
  •  无人共我
    2021-02-05 19:59

    replace + to %2B ios replace all + to " " space that make image invalid

    also backend must handle it too

    - (NSString *)base64String:(UIImage*)image {return [[UIImageJPEGRepresentation(image,1) base64EncodedStringWithOptions:NSDataBase64EncodingEndLineWithLineFeed] stringByReplacingOccurrencesOfString:@"+" withString:@"%2B"];}
    

提交回复
热议问题