Hello, could somebody explain my why QByteArray::fromBase64() does not work if input data contains whitespaces ?

For example I've got attachment contains binary data (Jpeg image or something) and file looks that:

Qt Code:
  1. JMZDPEtHBFh0BplzQ+AareD3FJUm//uUZOgAArYrS5s5GmBgBUlDawZMCjyNMUzgaUE1lSa1h400
  2. DsU0Z+hbxXKeC2sz267Ujb7bjvI9a8OrFA5vjdZTqFsTHVVp+fKfSNQclzKepQKxpEXWDg4j6urV
  3. u/f+4duXDyoaUdJy23+uk/LuCyGWCNYkGJwbSVScdafgyX9Iz9qtWFuR7fwn1GObEh4kYUM0jk4
  4. ..
  5. ..
  6. ..
To copy to clipboard, switch view to plain text mode 

When I try to decode it only does the first line...
How can I decode whole file ?

I tried QByteArray::fromBase64() and c++ function

(c++ function found on web)

Qt Code:
  1. static inline bool is_base64(unsigned char c) {
  2. return (isalnum(c) || (c == '+') || (c == '/'));
  3. }
  4.  
  5. static const std::string base64_chars =
  6. "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
  7. "abcdefghijklmnopqrstuvwxyz"
  8. "0123456789+/";
  9.  
  10. std::string MainWindow::base64_decode(std::string const& encoded_string)
  11. {
  12. int in_len = encoded_string.size();
  13. int i = 0;
  14. int j = 0;
  15. int in_ = 0;
  16. unsigned char char_array_4[4], char_array_3[3];
  17. std::string ret;
  18.  
  19. while (in_len-- && ( encoded_string[in_] != '=') && is_base64(encoded_string[in_])) {
  20. char_array_4[i++] = encoded_string[in_]; in_++;
  21. if (i ==4) {
  22. for (i = 0; i <4; i++)
  23. char_array_4[i] = base64_chars.find(char_array_4[i]);
  24.  
  25. char_array_3[0] = (char_array_4[0] << 2) + ((char_array_4[1] & 0x30) >> 4);
  26. char_array_3[1] = ((char_array_4[1] & 0xf) << 4) + ((char_array_4[2] & 0x3c) >> 2);
  27. char_array_3[2] = ((char_array_4[2] & 0x3) << 6) + char_array_4[3];
  28.  
  29. for (i = 0; (i < 3); i++)
  30. ret += char_array_3[i];
  31. i = 0;
  32. }
  33. }
  34.  
  35. if (i) {
  36. for (j = i; j <4; j++)
  37. char_array_4[j] = 0;
  38.  
  39. for (j = 0; j <4; j++)
  40. char_array_4[j] = base64_chars.find(char_array_4[j]);
  41.  
  42. char_array_3[0] = (char_array_4[0] << 2) + ((char_array_4[1] & 0x30) >> 4);
  43. char_array_3[1] = ((char_array_4[1] & 0xf) << 4) + ((char_array_4[2] & 0x3c) >> 2);
  44. char_array_3[2] = ((char_array_4[2] & 0x3) << 6) + char_array_4[3];
  45.  
  46. for (j = 0; (j < i - 1); j++) ret += char_array_3[j];
  47. }
  48.  
  49. return ret;
  50. }
To copy to clipboard, switch view to plain text mode 

I can't remove those whitespaces...

text.simplified();
text.replace("\\s", "").replace("\\n", "").replace("\\r", "").replace(" ", ;

Thank You for any help