Media Engine Examples

From EChase
Jump to: navigation, search

Uploading an Image (Byte array)[edit]

// Open up a webservice port to the mediaengine
MediaEngineService service = new MediaEngineServiceLocator();
MediaEnginePortType port = service.getMediaEngineSOAPPort(new   URL("http://localhost:8080/axis/services/MediaEngineSOAPPort"));

// The file to be uploaded
File image = new File("/home/ss1602/images/alinari/img/ACA-F-000388-0000.jpg");

// The idea is that we're reading an image into a bytearray
// Heres the output stream to the byte array
ByteArrayOutputStream baos = new ByteArrayOutputStream();
// Heres how we're reading the file
FileInputStream fileIn = new FileInputStream(image);

// While the bit being read isn't -1, write the bit to the byte output stream        
int bit;
while ((bit = fileIn.read()) != -1)
 baos.write(bit);
      
baos.flush();
baos.close();
        
// Grab the output stream's bytearray
byte[] sentImage = baos.toByteArray();

// Give the byte array to the medaiengine, get back the StoredItem
System.out.println("Uploading image");
StoredItem imageout = port.uploadItem(sentImage);