Reading files as binary data

Post any questions you have about using the Verj.io Studio, including client and server-side programming with Javascript or FPL, and integration with databases, web services etc.

Moderators: Jon, Steve, Ian, Dave

eddparsons
Ebase User
Posts: 53
Joined: Wed Jan 02, 2013 4:23 pm
Location: Lyndhurst, Hampshire
Contact:

Reading files as binary data

#1

Postby eddparsons » Thu Feb 06, 2014 10:39 am

Hi,

I have a web service inteface to a Document Management System that I can use to add a file to the DMS if it is encoded in base64Binary.

How can I take a file uploaded to Ebase, read it as a binary file stream and output that to the web service?

Regards,
Edd Parsons
0 x

Steve
Moderator
Moderator
Posts: 421
Joined: Fri Sep 07, 2007 3:44 pm
Location: Sandy, UK
Contact:

#2

Postby Steve » Thu Feb 06, 2014 11:56 am

Hi Edd,

I am afraid that this is not supported with the current Ebase web service resources.

You can create your own web service using CXF API (This is our underlying Web Service technology), providing there is a WSDL to import from the DMS.

http://cxf.apache.org/docs/wsdl-to-java.html demonstrates how to convert the WSDL into Java stub classes that you can populate using a custom resource or invoke directly using server side JavaScript.

http://cxf.apache.org/docs/how-do-i-dev ... lient.html demostrates how to create a CXF client and invoke the web service using your stub classes.

I hope this helps?

Steve
0 x

eddparsons
Ebase User
Posts: 53
Joined: Wed Jan 02, 2013 4:23 pm
Location: Lyndhurst, Hampshire
Contact:

#3

Postby eddparsons » Thu Feb 06, 2014 1:31 pm

Ok thanks Steve.

This may well be over my head but I will have a look and see what I can do.

Regards,
Edd
0 x

Steve
Moderator
Moderator
Posts: 421
Joined: Fri Sep 07, 2007 3:44 pm
Location: Sandy, UK
Contact:

#4

Postby Steve » Thu Feb 06, 2014 3:07 pm

Hi Edd,

I have been reading around this subject and you might be able to set the convert the data to base64 string and set this on your Web Service Document:

Using Java code you can:

Code: Select all

BufferedImage img = ImageIO.read(new File("image.png"));    
 ByteArrayOutputStream baos = new ByteArrayOutputStream();
 ImageIO.write(img, "png", baos);    
 baos.flush();
 String encodedImage = Base64.encodeToString(baos.toByteArray());
 baos.close(); // should be inside a finally block
note that encodedImage is a string and you can map this to a web service resource field.

Also Base64 can be found in the apache commons API.

Using the server side JavaScript:

Code: Select all


importPackage(java.io);
.......
//note need other imports here

var img = ImageIO.read(new File("image.png"));    
var baos = new ByteArrayOutputStream();
ImageIO.write(img, "png", baos);    
baos.flush();
var encodedImage = Base64.encodeToString(baos.toByteArray());
 baos.close(); // should be inside a finally block
I think this should work.

Steve
0 x

User avatar
dvanhussel
Ebase User
Posts: 161
Joined: Fri Oct 19, 2007 12:45 pm
Location: Haarlem, the Netherlands

#5

Postby dvanhussel » Tue Feb 11, 2014 12:13 pm

Steve wrote:Hi Edd,

I think this should work.

Steve
Yes, it should.

We do a similar thing with PDF's created by Ebase.

We pass these documents as as base64 encoded string to a webservice of a backoffice application.
0 x


Who is online

Users browsing this forum: No registered users and 17 guests