Situation:
I am able to encode a file to base64 format and I can send it to a pdf conversion webservice, but I want to decode the result (its a new pdf file) from base64 to its original content.
Solution:
1) Use the following code in a custom plugin
import java.io.*;
import org.apache.commons.codec.binary.Base64;OutputStream os = service.getOutputStream();
int i = -1;
byte[] b = new byte[4096];
ByteArrayOutputStream baos = new ByteArrayOutputStream();
while ((i = inputStream.read(b)) != -1) {
baos.write(b, 0, i);
}byte[] encoded = Base64.decodeBase64(baos.toByteArray());
os.write(encoded);
os.flush();
2) Open Properties of Custom Plugin activity and set consume stream to true and generate stream to true.
3) Provide explicit stream to file target from Custom Plugin activity.
Comments
1 comment
Quick tip: In this example, the base64 encoded data should be set to the context variable "inputStream"
Article is closed for comments.