Page 1 of 1

Archived original files

PostPosted: Mon May 24, 2010 3:54 pm
by johnjhufnagle
Hi,

If the user, at import time, chooses the "Archive the original imported files(s) to the server" option, is there a way through the API to get those files either as bytes or perhaps the file path(s) that the client app can then access through the file system?

Thanks
John

Re: Archived original files

PostPosted: Thu May 27, 2010 2:15 pm
by jburel
Hi John
If the user selects the archived option, to retrieve the files you can do:
Use the Query service to retrieve the original files linked to a given pixels set.
You will get the pixels ID from the image itself.
Code: Select all
IQueryPrx service;
ParametersI param = new ParametersI();
param.map.put("id", omero.rtypes.rlong(pixelsID));
List files = service.findAllByQuery(
               "select ofile from OriginalFile as ofile left join " +
               "ofile.pixelsFileMaps as pfm left join pfm.child as " +
               "child where child.id = :id", param);

The call will return a collection of Original files.

Then you can read the data using the RawFileStore
Follow some pseudo-code

Code: Select all
int INC = 262144;
RawFileStorePrx store;
File f;// The file on client's machine
OriginalFile of; //object from the list returned in previous call.
store.setFileId(of.getId().getValue());
stream = new FileOutputStream(f);
size = of.getSize().getValue();
try {
   for (offset = 0; (offset+INC) < size;) {
       stream.write(store.read(offset, INC)); //read the data
      offset += INC;
    }               
} finally {
stream.write(store.read(offset, (int) (size-offset)));
stream.close();
}            




I will probably need to make the method available through one of the services, so it is easier to use.

Thanks
jmarie

Re: Archived original files

PostPosted: Mon Jun 28, 2010 5:30 pm
by johnjhufnagle
Thank you JMarie that worked nicely!