Subversion Repositories SmartDukaan

Rev

Rev 30935 | View as "text/plain" | Blame | Compare with Previous | Last modification | View Log | RSS feed

package com.smartdukaan.cron.scheduled;

import com.spice.profitmandi.common.web.client.RestClient;
import org.apache.commons.io.FileUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.File;
import java.util.Base64;
import java.util.HashMap;

@Service
public class CaptchaService {

        @Autowired
        RestClient restClient;
        private static final Logger LOGGER = LogManager.getLogger(CaptchaService.class);

        public String getCaptchaCode(String filePath) throws Exception {
                byte[] fileContent = FileUtils.readFileToByteArray(new File(filePath));
                String encodedString = Base64.getEncoder().encodeToString(fileContent);
                System.out.println(encodedString);
                Base64Image base64Image = new Base64Image();
                base64Image.setImage(encodedString);
                return restClient.postJson("http://45.79.121.178/uploader", base64Image, new HashMap<>());
        }

        class Base64Image {
                private String image;

                public String getImage() {
                        return image;
                }

                public void setImage(String image) {
                        this.image = image;
                }
        }

}