Answers for "java encode image to base64 string"

0

java:image to base64 string example

       public static void main(String[] args) throws Exception{
 
           File f =  new File("/opt/myImage.jpg");
             String encodstring = encodeFileToBase64Binary(f);
             System.out.println(encodstring);
       }
 
       private static String encodeFileToBase64Binary(File file) throws Exception{
            FileInputStream fileInputStreamReader = new FileInputStream(file);
            byte[] bytes = new byte[(int)file.length()];
            fileInputStreamReader.read(bytes);
            return new String(Base64.encodeBase64(bytes), "UTF-8");
        }
Posted by: Guest on June-10-2021
-1

converting image to base64 string

router.post('/upload',function(req,res){
var base64ToBuffer = new Buffer(req.image, 'base64');//Convert to base64

//Write your insertcode of MongoDb

res.end("Image uploaded Successfully"); 
});
Posted by: Guest on May-23-2021

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language