0

My question seems to be a general problem but actually it is not.

We have a DEV environment, in which we have the FrontEnd running that is communicating with the BE. If the user is on the FE and gives inputs like name, surname, city and zipcode, then based on these inputs the Backend will generate an QR Code as png file.

This png file is saved locally in src/main/....

The problem: How can I access this file so that I can show the QR Code to the user in the FE.This image that is located on my HDD should be delivered to the FE.

What I have tried:

How to reference a local image in java?

Trying to cast an Image to a BufferedImage

ClassPathResource does not get the classpath

Nothing worked. The image won't shown.

Blnpwr
  • 1,793
  • 4
  • 22
  • 43

1 Answers1

1

You should not be saving files under src/main/... directory. This location is valid for only during local development when you are using a build tool like Maven. When the application get's packaged this directory is no longer present.

You want to save the image somewhere on the hard drive e.g. using File.createTempFile(). You most likely want to create a new API in the backed to return this file e.g. for POST /api/user/{id}/qrcode you want to respond with Content-type: image/png and the QR code image.

Karol Dowbecki
  • 43,645
  • 9
  • 78
  • 111
  • Yes, I am using Maven, too. Do you know any good API for that? Why does ResourceLoader not work in this case ? – Blnpwr May 07 '19 at 10:43