Swift Encode/decode emojis

Your encoding code can be simplified to func encode(_ s: String) -> String { let data = s.data(using: .nonLossyASCII, allowLossyConversion: true)! return String(data: data, encoding: .utf8)! } Note that it encodes all non-ASCII characters not only Emojis (as \uNNNN where NNNN is the hexadecimal code of the Unicode character, or as \NNN where NNN is … Read more

Converting object to an encodable object failed

You don’t need to add any libraries. You just have to implement fromJson and toJson functions in your object. Example: class LinkItem { final String name; final String url; LinkItem({this.name, this.url}); LinkItem.fromJson(Map<String, dynamic> json) : name = json[‘n’], url = json[‘u’]; Map<String, dynamic> toJson() { return { ‘n’: name, ‘u’: url, }; } } Then … Read more

PHP get pdf file from base64 encoded data string

Try this piece of code $pdf_base64 = “base64pdf.txt”; //Get File content from txt file $pdf_base64_handler = fopen($pdf_base64,’r’); $pdf_content = fread ($pdf_base64_handler,filesize($pdf_base64)); fclose ($pdf_base64_handler); //Decode pdf content $pdf_decoded = base64_decode ($pdf_content); //Write data back to pdf file $pdf = fopen (‘test.pdf’,’w’); fwrite ($pdf,$pdf_decoded); //close output file fclose ($pdf); echo ‘Done’;

Write Base64-encoded image to file

Assuming the image data is already in the format you want, you don’t need ImageIO at all – you just need to write the data to the file: // Note preferred way of declaring an array variable byte[] data = Base64.decodeBase64(crntImage); try (OutputStream stream = new FileOutputStream(“c:/decode/abc.bmp”)) { stream.write(data); } (I’m assuming you’re using Java … Read more