kenglxn / QRGen

a simple QRCode generation api for java built on top ZXING
http://glxn.net/2012/03/10/qrgen-a-small-wrapper-on-top-of-zxing-for-generating-qrcodes-in-java
1.49k stars 299 forks source link

Compatibility with Google App Engine #80

Closed csacanam closed 8 years ago

csacanam commented 8 years ago

I'm writing a web app with Google App Engine. I found your library and I'm very interested in using it to generate QR codes. However I have an exception because you're creating a temporary file when I use

File file = QRCode.from("Hello World").file();

It generate a net.glxn.qrgen.core.exception.QRGenerationException

Do u know how can I solve this issue?

atomfrede commented 8 years ago

I don't know app engine, but if you can't create a temporary file you can use QRCode.from("Hello World").stream() to obtain a ByteArrayOutputStream and convert it yourself to a file (if required).

csacanam commented 8 years ago

I tried it but now I receive another exception: java.lang.NoClassDefFoundError: java.awt.Image is a restricted class. Please see the Google App Engine developer's guide for more details. Line 150 in QRCode.java and Line 62 in AbstractQRCode.java.

kenglxn commented 8 years ago

I don't think that error is from QRGen, but a stacktrace would be helpful to be sure. It seems like you are using java.awt.Image which is not whitelisted in GAE. They have some examples for manipulating images here: https://cloud.google.com/appengine/docs/java/images/

I have not played around with GAE myself, but it looks like you can give a byte array to ImagesServiceFactory.makeImage(imagebytes) You can probably combine that with .stream as @atomfrede mentioned above. (Example in the test suite)

...perhaps something like:

byte[] imageData = QRCode.from("Hello World").stream().toByteArray();
return ImagesServiceFactory.makeImage(imageData)
kenglxn commented 8 years ago

@csacanam can you confirm that this works?

I can't really see why QRGen would be incompatible with GAE.

kenglxn commented 8 years ago

I'm closing this, as I don't see how this can be aproblem caused by QRGen.

Feel free to reopen if you disagree.