Sie können mich buchen für:
Individuelle Schulungen für XPages, JavaScript und Appcelerator Titanium Software-Entwicklung für IBM XPages, Appcelerator Titanium (Mobile Apps iPhone, iPad, Android, Blackberry 10), Mobile Web und IBM Notes
Coming in Domino To Go 1.2: take photos with the iPhone or iPad camera and attach it to a NotesDocument - and general attachment support
Julian Buss, June 5th, 2012 11:55:24
Tags:  dominotogo  Lotus Domino 
You know our solution for developing native, offline capable mobile Apps for iPhone, iPad and Android (in the near future), do you? If not, click here to learn about Domino To Go!.

We are working on version 1.2 of Domino To Go. While we already had some support for downloading Notes document attachments to the mobile iOS device, there was room for improvement. Furthermore, we didn't had a sample for using the camera and attaching a photo to a Notes document.

So in version 1.2 of Domino To Go, there will be a lot of improvements in this area.

Using the camera


There are many usecases where you want to use the camera of your iPhone, iPad or Android device to take a photo and attach this photo to a specific Notes document. Actually that means you want to take the photo, store it on the mobile device, upload it to your Lotus Notes or XPages application and attach it to a Notes document in that application.

If you dig down into this requirement, there is a lot of complicated stuff to handle, like wrapping the file in base64 encoding, upload to Domino, decode it again and store it in a notes item, or uploading multiple files for multiple documents.

In Domino To Go 1.2, you will be able to solve this usecase with code like this:

App.window_content.
takePhoto = function() {
       
try {
               
// callback
               
var f function(e) {
                       
if (e.mediaType == Ti.Media.MEDIA_TYPE_PHOTO) {
                               
// we got a photo
                               
var f Ti.Filesystem.getFile(Ti.Filesystem.applicationDataDirectory, "photo.jpg");
                               
f.write(e.media);
                               
var doc App.notesdb.getDocumentByUNID(App.window_content.currentUNID);
                               
doc.setAttachment("fieldname", Ti.Filesystem.applicationDataDirectory+"photo.jpg");
                               
doc.save();
                       
}
               }
;
               
// show the camera and if the user made a photo, the callback will be executed
               Ti.Media.showCamera({

                       success: f

               })
;        
       }
catch (e) {
               YN.exception(
"App.window_content.takePhoto", e);
       }

}



So you only need to:
  • Use Ti.Media.showCamera() to open the camera app on the mobile device
  • Define a callback function to execute when the user made a photo
  • In the callback, write the binary photo data to a file in the mobile device's filesystem
  • Get the locally cached version of a Notes document using Domino To Go's NotesDatabase.getDocumentByUNID() method
  • Attach the file with Domino To Go's NotesDocument.setAttachment() method.
  • Save the document with Domino To Go's NotesDocument.save() method.

And when the next synchronization between the mobile device and Domino runs (that is, when a method called NotesDatabase.uploadChanges() is executed), the files will be uploaded and attached to the appropriate NotesDocument.

You can attach multiple files to the same document, even to the same notes item in the document. The upload process is robust, if there is a network problem then the files that has not been transferred so far will be uploaded again in the next sync.

More Attachment Handling


You will be able to use NotesDocument.setAttachment() for any kind of files, not only those take from the camera.
Furthermore, there will be the option to download attachments from a NotesDocument to the mobile device, and to work with the attachment on the mobile device.

So alltogether, there will be the following new methods in Domino To Go 1.2:

NotesDocument.setAttachment(filename, itemname)
NotesDocument.getAttachment(filename)
NotesDocument.removeAttachment(filename)

No Worries


The three methods above is all you need, you don't need to worry about how to upload, download and store file attachments on the mobile device. Domino To Go does it all for you. I don't think it can get easier than that :-)

Read more about Domino To Go!.
Comments (0) | Permanent Link

Comments:
No Comments Found
Add a comment
Subject:
   
Name:
Mail:
Web:
 
Comment:  (No HTML - URLs with leading http://)
 
remember me?   
You can hire me.
See my Linkedin profile for details.

Thanks for reading and have a nice time here!

Please note my Apps for iPhone and iPad: NotesBook: takes your Lotus Notes Notebook (Journal) to your iPhone and iPad xpageswiki.com: huge XPages Tips & Tricks collection for iPhone and iPad