Vijayakumar Vijayakumar - 4 months ago 58
AngularJS Question

File upload using angular js in lotus notes html form

I am using lotus notes form as .html files and I am sending values to server as json using angular js. But I want to upload files also now. How can I send files to server and extract using lotus script?

Can you please help me someone?

Like the below post. But it is done in ASP.NET . I want to do the same using lotus notes.

File uploading angular js ASP .NET

index.html

<span ng-if="quests.type == '17'">
<input type="file" file-upload multiple id='{{quests.id}}'/>
</span>

<button type="button" ng-click="submitForm();">Submit</button>


The above button will trigger the below code to executed.

Angular Code to post to server

var email=document.getElementById("email").value;
var message={"requesttype": "saveForm","email": emailid,"username": username};
$http.post("http://test.com/ajaxprocess?openagent", message).success(success).error(failure);


The above mentioned agent(lotusscript) will parse the above json and save the document as shown below.

ajaxprocess Agent code

'getting document context
Set docContext = sess.DocumentContext
If docContext.hasItem("REQUEST_CONTENT") Or docContext.hasItem("REQUEST_CONTENT_000") Then
'using openNTF lotus script classes to parse document to json object
Set userDataInfo=getJSONObjectFromDocument(docContext, "")
Dim fieldsobj As New JSONArray
'getting the fields array sent as json array
Set fieldsobj=userDataInfo.GetItemValue("fields")
fieldtype=Field.mGetItemValue("type")(0)
Dim doc As NotesDocument
Dim fieldname As String
ForAll Field In fieldsobj.Items
fieldname=Field.mGetItemValue("Fieldname")(0)
Call doc.Replaceitemvalue(fieldname,Field.mGetItemValue("value")(0))
End ForAll
call doc.save(true,false)
End If


Everything works fine expect file attachments. How can I send files to server with json and save using lotus script or is there any other workaround is there?

Answer

I finally found tip and made the solution as follows to get the base64 String and convert to attachment in lotusscript.

http://www-10.lotus.com/ldd/bpmpblog.nsf/dx/creating-a-mime-email-with-attachment?opendocument&comments

Dim s As New NotesSession
 Dim stream As NotesStream
 Dim body As NotesMIMEEntity
 Dim header As NotesMIMEHeader
 Dim StringInBase64 As String
 StringInBase64=getbase64() 'your base64 string
 Dim db As NotesDatabase
 Set db=s.Currentdatabase
 Dim tempdoc As NotesDocument
Set tempdoc=db.Createdocument()
Set stream = s.CreateStream
Call stream.WriteText(StringInBase64)
Set body = tempdoc.CreateMIMEEntity
Set header = body.createHeader("content-disposition")
Call header.setHeaderVal({attachment;filename="Onchange.xlsx"}) ' file name and type should be configurable
Call body.SetContentFromText(stream, "", ENC_BASE64)
Call stream.Close
tempdoc.form="Attachment"
Call tempdoc.save(True,False)

This works as expected. Thanks all for time you spent.