Hi BK,
The "conn" connection is the Blitz Gateway as described
http://trac.openmicroscopy.org.uk/ome/w ... Py/Gateway. Under "The Gateway Methods" you'll find links to the "conn" API and the method you're looking for:
http://hudson.openmicroscopy.org.uk/job ... mLocalFileHowever, I believe that you're using 4.2.1 and that method is only in the 4.3 release. 4.2 "conn" API is
http://hudson.openmicroscopy.org.uk/vie ... class.html.
You have a couple of choices: You can look at the code for that method in the 4.3 Blitz gateway and port it to your 4.2.1 code. The best place to put it would be in you own Blitz Gateway subclass, in the same way that the web client has extend Blitz Gateway with omeroweb/webclient/webclient_gateway.py. If this seems a bit too tricky then put it somewhere else that makes sense to you.
This code is based on the method you mentioned in script_utils.py. You could look there at the other available methods and you should see that there are ways to create a file attachment and upload file without adding the annotation to any parent.
The code for uploadAndAttachFile looks like this:
- Code: Select all
filename = localName
if origFilePathName == None:
origFilePathName = localName
originalFile = createFile(updateService, filename, mimetype, origFilePathName)
uploadFile(rawFileStore, originalFile, localName)
fileLink = attachFileToParent(updateService, parent, originalFile, description, namespace)
return fileLink.getChild()
So you could simply do
- Code: Select all
originalFile = script_utils.createFile(updateService, filename, mimetype, origFilePathName)
script.utils.uploadFile(rawFileStore, originalFile, localName)
If you wanted this to be a FileAnnotation instead of a regular OriginalFile, you could do
- Code: Select all
fa = omero.model.FileAnnotationI()
fa.setFile(originalFile)
fa.setDescription(rstring(desc))
fa.setNs(rstring(ns))
fa = updateService.saveAndReturnObject(fa)
To download that file, you can use
- Code: Select all
fa = conn.getFileAnnotation(annId)
To provide the file as a download from the web, this is how the webclient does it:
- Code: Select all
@isUserConnected
def download_annotation(request, action, iid, **kwargs):
conn = None
try:
conn = kwargs["conn"]
except:
logger.error(traceback.format_exc())
return handlerInternalError("Connection is not available. Please contact your administrator.")
try:
# ann = conn.getObject("Annotation", long(iid)) # 4.3 API
ann = conn.getFileAnnotation(annId) # This is with 4.2 API
from django.conf import settings
tempdir = settings.FILE_UPLOAD_TEMP_DIR
temp = os.path.join(tempdir, ('%i-%s.download' % (ann.file.id.val, conn._sessionUuid))).replace('\\','/')
logger.info("temp path: %s" % str(temp))
f = open(str(temp),"wb")
for piece in ann.getFileInChunks():
f.write(piece)
f.seek(0)
from django.core.servers.basehttp import FileWrapper
originalFile_data = FileWrapper(file(temp))
except Exception, x:
logger.error(traceback.format_exc())
return handlerInternalError("Cannot download annotation (id:%s)." % (iid))
rsp = HttpResponse(originalFile_data)
if originalFile_data is None:
return handlerInternalError("Cannot download annotation (id:%s)." % (iid))
if action == 'download':
rsp['Content-Type'] = 'application/force-download'
rsp['Content-Length'] = ann.getFileSize()
rsp['Content-Disposition'] = 'attachment; filename=%s' % (ann.getFileName().replace(" ","_"))
return rsp
I'm not sure what this code looked like in 4.2.1, but if it's similar, you could provide a "download" link on your pages with
- Code: Select all
<a href="{% url download_annotation 'download' annId %}" > Download </a>
I assume IObjectList in Python is simply a list of IObjects, E.g.
- Code: Select all
a = omero.model.DatasetI(dsId)
b = omero.model.ImageI(iId)
list = [a, b]
Will.