解码iOS编码的Java文件(Base64)

时间:2013-10-25 17:15:05

标签: java ios rest encoding decode

我在Java中创建一个RESTFul服务,从Base-64接收iPhone字符串。

但是我无法在服务器端重新生成文件。

我使用了以下一些代码,但所有代码都不适用于我。

ONE

File fileOut = new File("/home/xyz/fileOutPNG.png");
FileUtils.writeByteArrayToFile(fileOut, Base64.decodeBase64(fileString));

TWO

File fileOut = new File("/home/xyz/fileOutPNG.png");
FileUtils.writeByteArrayToFile(fileOut, fileString.getBytes());

BASE64Decoder decoder = new BASE64Decoder();

File fileOut = new File("/home/xyz/fileOutPNG.png");
FileUtils.writeByteArrayToFile(fileOut, decoder.decodeBuffer(fileString));

有人可以告诉我如何创建图像。

供参考fileString包含以下编码字符串。

"iVBORw0KGgoAAAANSUhEUgAAAGQAAAClCAYAAACqVlhFAAAAHGlET1QAAAACAAAAAAAAAFMAAAAoAAAAUwAAAFIAAA P0RNzfgAAD1tJREFUeAHsnHmQFcUdxxcPVKLxSNR4RNSQMgke3IfBsGoqGkuUEtcFxXW5wRLPWF5RVxPUJKCmNDHGVYhbyKHhZgUxYjQhBjFIPEiCBmJUEIgGF1Fg2ZfPb v1q98Ob95098y8fWvlj191z8yvf9e3r numbJMJlP2fyqdGLQKGIsWLTpi3rx550O3LViw4In58 cvg9ZBW6FMgD7i i3oeWgKdD1lzpo9e/ZBn8eKVBRA6uvr9yH45xLMh6C3oWDQfa6bkLMKcH4GnVZTU7PH5wGgVAFZuHBhb4L2KLQlIRAKAfe gDN37twT2jIwiQMiNZXgV9IiXo4AYTU8dQTxVtKLAK8HwewEHb548eIvkB4AHQmdIMDCcynyfgQ9Bf0rQnY9z8vbIjCJAkIQBkJvhgRLWskUAjuEAH8lbrAAqhPyRkKzoO1QvtYj406vuLqKWT4RQKQW4/jv8gUFAJ7mfuXMmTP3S8sxWtnB6BmDnuX5bODebxjHDk1Lf5JyYwFCkPfE2RuhzwKBaOR6GoE6MUljbWShtxxaErBHWs9/sGewjYzW5PEGJDt1/X0ex2d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ZzxEDaNAKs7AVqfHbHkDZHPg700BoBBffof99MctQoP9ab4AEUABkTYahrPcKCI1BH3wGgMT9WYBzmVWoAW33DggNQvY1J2SkywCiuvFV5VNoQ bHkKBlcSvWen2TRShcJOcdEBqEKJmXRSAY2Gd5CQQweCs4iwsmrvcSiIiS1VmLEiy0nvz3Hq/GEMJgQfjfkjEge4PX/XkJRLy69s MQBlHA5odNCYvgdA4wDD9f4fR1FVlfwQwbgxgcOstEBhacThC OqqVzDDe14YhtdAxJ YfekYFL4BfBlS85lREMG txFCAxEl1zkCZCf0eDT89tEAQHTrNRABZW1KUEYQCctR uNeEJ07IIDBNV6fWIKyFXKeBYSrg9e Rh1eb9/7CKEDxIs5H4OzdL4dexfqW4Nu8QmU2Um6o3ow H0ugASO4B1GOO9WOJJrvRg1fAXhGEo4Zf0N ztQmBC8hzKEMohyH1r Dfh9O69zgjp1b/8D66csbZyrQs4AAAAASUVORK5CYII="

1 个答案:

答案 0 :(得分:1)

尝试下一个:

File fileOut = new File("/home/xyz/fileOutPNG.png");
FileUtils.writeByteArrayToFile(fileOut, 
                 javax.xml.bind.DatatypeConverter.parseBase64Binary(fileString));