ios - Cannot decode Base64 string swift -


i'm trying decode following base64 encoded string :

/9j/4aaqskzjrgabaqaasabiaad/4qbyrxhpzgaatu0akgaaaagaagesaamaaaabaaeaaidpaaqaaaabaaaajgaaaaaaa6abaamaaaabaaeaakacaaqaaaabaaaazkadaaqaaaabaaaazaaaaad/7qa4ughvdg9zag9widmumaa4qklnbaqaaaaaaaa4qklnbcuaaaaaabduhyzzjwcybomaczjs%2bej%2b/8aaeqgazabkaweiaairaqmraf/eab8aaaefaqebaqebaaaaaaaaaaabagmebqyhcakkc//ealuqaaibawmcbamfbqqeaaabfqecawaeequsitfbbhnryqcicrqygzghccncscevuthwjdnicoijchyxgbkajsynkckqndu2nzg5okneruzhselku1rvvldywvpjzgvmz2hpann0dxz3ehl6g4sfhoeiiyqsk5svlpeymzqio6slpqeoqaqys7s1tre4ubrcw8tfxsfiycrs09tv1tfy2drh4upk5ebn6onq8flz9px29/j5%2bv/eab8baambaqebaqebaqeaaaaaaaabagmebqyhcakkc//ealuraaibagqeawqhbqqeaaecdwabagmrbauhmqysqvehyxetijkbcbrckagxwqkjm1lwfwjy0qowjdthjfexgbkajicokso1njc4otpdrevgr0hjslnuvvzxwflay2rlzmdoawpzdhv2d3h5eokdhiwgh4ijipktljwwl5izmqkjpkwmp6ipqrkztlw2t7i5usldxmxgx8jjytlt1nxw19jz2ulj5oxm5%2bjp6vlz9px29/j5%2bv/baemabgygbgygcgygcg4kcgooeg4odg4sfxisehisfxwxfxcxfxcchbwchbwchciiiiiiiicnjycnlcwslcwslcwslp/baembbwchcwolewokey4fgh8uli4uli4uli4uli4uli4uli4uli4uli4uli4uli4uli4uli4uli4uli4uli4uli4ulv/daaqab//aaawdaqaceqmrad8a5rrzq3apwpporxkbnqsrt%2blsz/worx0p2t0oepy0ufsoycine/nsep8aapfqhduye4oepj4pm7pwkj600dkagtdptxzmoh6vjnahvt8xodlh0o3p/nnjn8atpsfypduf/9dlscc1esm1xknudinv/tipf2rybm9rsv8aendqpc4bfsczsdzq0xxlqx%2btixzue8c0p5anlurmd39qnhtvvxhspqwpfkwhxpu03dtxubpjj0qfnlnj0q0beu0pfnnvefjnpdzofshizz3ubvaq4zu1llvwpsvy/9hyh5ye9v2mpy1satioml9a4la9bs1ptldvugvckxpmnjvprt5es5m6qxw45xu5vwrjncr5ll5vpwj2afznvlfdd1quxwx1rkhmc9aczyo9t7jbznum%2bx1puuhk%2b9ckzzkdpvu8dyqetp2yc52czdircsmzrl47v3rsgus8vdgajmyccdcuc%2btu/nlcgmjefu1nzlh/0vcc1rliazmjnc52dt3fgaytse0xdy1juphngayh%2b7fg4mme00mhity/jzmpaxfqcnzp2bftxi71aiucvoayw1sb6mw7nrldgr1ip32of3jwd5jdpr5r%2btz%2bzk52f//t%2bfc96xpfipekjra6x2ekaemktnjnmmidmgu2lzqim%2bljnmkjpuaaepzs7qjzxs54pgpyelgcgm03pnafkov8vlvsqxoatipwc5//1pn3nnptsdqaaxopsdtam8uuxcmlpbtscgmicaq0ugoelmkbpvenuwfjpac00mlfac4j6uu003njqb//1fnjp8qtnh%2bfb7vkjqy3pfo7uw9kf/hqsgzxtg60/wdhpjdaoga5fgab92k9kbc44zsdqd2pg6uwfpdxs0jdkagnrszobrsuaf/z

it valid have tested using online base64 image converter , displays fine. use following code :

let thumbdata = nsdata(base64encodedstring: thumbnaill, options: nsdatabase64decodingoptions(rawvalue: 0)) if let b = thumbdata {  let thumb = uiimage(data: b)  curr_item.thumbnail = thumb  }               

the problem thumbdata nil. i'm not sure i'm doing wrong.

the "base64" data provided above url-encoded. e.g. has %2b in place of "+" characters. if that's not copy/paste error, , actual data url-encoded, need remove encoding first before decoding it. this:

if let decoded = thumbnaill.stringbyremovingpercentencoding {   let thumbdata = nsdata(base64encodedstring: decoded, options: nsdatabase64decodingoptions(rawvalue: 0)) } else {   print("couldn't decode string") } 

Comments

Popular posts from this blog

wordpress - (T_ENDFOREACH) php error -

Export Excel workseet into txt file using vba - (text and numbers with formulas) -

Using django-mptt to get only the categories that have items -