I am trying to save images on firebase using code below.
Bitmap bm = BitmapFactory.decodeFile(imgDecodableString);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bm.compress(Bitmap.CompressFormat.JPEG,100,baos);
byte[] byteArray = baos.toByteArray();
String encodedImage = Base64.encodeToString(byteArray,Base64.DEFAULT);
But i am facing an error :
cannot resolve method 'encodeToString(byte[],?)'
cannot resolve symbol 'DEFAULT'
How to fix this error.
Once the Base64 API is created, both encoding and decoding are quite simple: Moreover, the decode () method of the Base64 class returns the decoded string: Another option is using the static API of Base64 instead of creating an instance: 4.
Base64 is a binary-to-text encoding scheme that represents binary data in a printable ASCII string format. In this article, you’ll learn how to Base64 encode any arbitrary text in Java using the Base64 API that was introduced in Java 8.
Base64 (int lineLength) creates the Base64 API in a URL-unsafe mode and controls the length of the line (default is 76). Base64 (int lineLength, byte [] lineSeparator) creates the Base64 API by accepting an extra line separator, which by default is CRLF (“ ”).
The basic Base64.getEncoder() function provided by the Base64 API uses the standard Base64 alphabet that contains characters A-Z, a-z, 0-9, +, and /. Since + and / characters are not URL and filename safe, The RFC 4648 defines another variant of Base64 encoding whose output is URL and Filename safe.
I think you have import org.apache.commons.codec.binary.Base64 in your file, please re-check and instead try using import android.util.Base64. It will resolve your problem for cannot resolve method 'encodeToString(byte[],?)'.
Try it:
val encodedImage = encodeToString(b, DEFAULT)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With