0

I'm working on a spring boot application in which I have to generate some QR codes using Zxing library in one of the folders of my resources and creating a zip file and further deleting those QR code .png images. I'm able to do it in localhost, however, when I deployed the application on Heroku it is unable to locate the path Below is my code:

private void createQrCode(String data, String fileName) {
        String charset = "UTF-8"; // or "ISO-8859-1"
        Map hintMap = new HashMap();
        hintMap.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.L);

        try {

            BitMatrix matrix = new MultiFormatWriter().encode(new String(data.getBytes(charset), charset),
                    BarcodeFormat.QR_CODE, 400, 400, hintMap);
            File file = new File("./src/main/resources/qr/"+fileName+".png");
            MatrixToImageWriter.writeToFile(matrix, "png", file);
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (WriterException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } 

    }

I understand that I have given path in wrong way becuase when it will be packaged as jar, resources will be moved to a path which cannot be accessed like this. I'm looking for the solution for the same. Please help me out. Thanks in advance.

EDIT:

It is different from the asked question as in all the question people asked about reading a resource however in this question I'm asking about writing a resource that too using Zxing library which might be a issue here.

Siddharth Sachdeva
  • 1,812
  • 1
  • 20
  • 29

0 Answers0