Mike B Mike B - 3 months ago 6
Ajax Question

Is it possible to upload an image file using AJAX to Domino Server?

Is it possible to upload an image file using AJAX to Domino Server? I am trying to upload a photo from Android phone. I can send the image data back to a rich text field in Domino. But I am not sure how to render it as an image on the Domino Form. Ideally I'd like to send the photo via ajax and have it attached to the Domino document as to a $File field.

The only example that is even close is here: http://markwambler.blogspot.com/2009/10/webcam-snapshots-and-lotusdomino.html

Thanks in advance. I have been struggling on this for days.


So if you are able to send a Base64 encoded version to a rich text field and you want to display it via a browser then you have a couple of things to do.

  1. Make sure that you are creating your document using MIME.
  2. Create a MIME entity for the attachment.
  3. Populate the MIME entity with the Base64 string.
  4. Decode it into a regular file attachment on the document.

This will give you a regular Domino document with an attachment that you can create a URL and to link to.

This is essentially what the linked example code is doing. Namely:

Set child = parent.CreateChildEntity()
Set header = child.CreateHeader("Content-Disposition")
Call header.SetHeaderVal({attachment; filename="} & fileName & {"})
Call child.SetContentFromText(stream, "image/jpeg", ENC_BASE64)
Call child.DecodeContent()

Once you have saved the document then it is trivial to arrange a link to the attachment url with something like db.nsf/viewname/dockey/$file/filename.jpg or put the url in an img src parameter.

Not having a set up to play with at the moment it's a little difficult to test. I also suspect it would be better if you could mimic a regular file upload from the client. In that case you would not need to mess about with Base64 and MIME with the 1.3x expansion over the wire that gives.