I recived secured image from api which is basically Base64Binary and it doesn’t decode with only base64 conversion. it shows format exception. I am looking for solution in flutter. my format is
"/4AAQSkZJRgABAQEAYABgAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0aHBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL/2wBDAQkJCQwLDBgNDRgyIRwhMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjL/wAARCADIAJYDASIAAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQAAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uHi4+Tl5ufo6erx8vP09fb3+Pn6/8QAHwEAAwEBAQEBAQEBAQAAAAAAAAECAwQFBgcICQoL/8QAtREAAgECBAQDBAcFBAQAAQJ3AAECAxEEBSExBhJBUQdhcRMiMoEIFEKRobHBCSMzUvAVYnLRChYkNOEl8RcYGRomJygpKjU2Nzg5OkNERUZHSElKU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6goOEhYaHiImKkpOUlZaXmJmaoqOkpaanqKmqsrO0tba3uLm6wsPExcbHyMnK0tPU1dbX2Nna4uPk5ebn6Onq8vP09fb3+Pn6/9oADAMBAAIRAxEAPwD2/Lbz8x608M394/nTSPnb608CtiBwJ9T+dKc+poFP3cYxUgMBPqaerU2ikwJc5pGzikU4pWYYqQIyT6n86TJ9T+dRz3MFuheeaONfV2AFZknivQIjh9XswfQSg1YzXyfU/nRk+p/Os611/Sb1tttqNtK3okoJ/KtFWVh8pBoAOfU/nS5Pqfzooo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wiPPPQkk+tFFc7ijdSdh+WHzeW7H3GBUf+kyvjbgewzRRUDLkFmw+Yoxb1NXIomXkqc/SiigTZPFbvI2SMDPetBVCjAHFFFdtGKsc827i0UUVuQFFFFAH/9k="
I tried only base64 conversion and it doesn’t work for me it shows format exception. My format is right. I want to convert this type of format to jpg or image and display it in flutter
2
Answers
You can use the Image.memory widget along with the dart:convert library to decode the base64 string into bytes
Then use like this:
you can receive a Base64 encoded image from an API and it fails to decode correctly, there could be several reasons why you’re getting a format exception.
Here’s a step-by-step solution to handle and display the Base64 image
Make sure the Base64 string is valid and properly formatted. If it has a prefix, you should include it. For example:
If your string is without the prefix, add it manually:
Step 2: Decode and Display Image
Here’s how you can decode the Base64 string and display it as an image in your Flutter app:
Step 3: Error Handling
To handle errors and ensure the Base64 string is valid, you can add some error handling: