0

I referred to remove whitespaces from base64 encoded string when posting but still I have this problem

I am currently using the following code :

NSString *TrimBase64String=[base64String stringByReplacingOccurrencesOfString:@" " withString:@""];
Community
  • 1
  • 1
MacBoy
  • 11
  • 6

3 Answers3

0

Easy Peasy, use this line:

NSString *TrimBase64String=[base64String stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
Flavio Silverio
  • 1,004
  • 8
  • 12
  • This should remove the white space characters that are at the begining or at the end only, not the one in the middle. – Larme Jun 21 '16 at 18:41
0

Use below lines of code to create NSString with Base64 Encoding to avoid white spaces and then post it:

NSString *strbase64 = [YourNSData base64EncodedStringWithOptions:NSDataBase64EncodingEndLineWithLineFeed];

Check answer here, may be it will help more:

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

Community
  • 1
  • 1
Ronak Chaniyara
  • 5,335
  • 3
  • 24
  • 51
0

I tried many ways and finally found the cause of the problem is the character \r

\r = CR (Carriage Return) // Used as a new line character in Mac OS before X`

[yourBase64String stringByReplacingOccurrencesOfString:@"\r" withString:@""];

jose920405
  • 7,982
  • 6
  • 45
  • 71