Vijayakumar Vijayakumar - 2 months ago 35
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


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

<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};
$"", 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")
Dim doc As NotesDocument
Dim fieldname As String
ForAll Field In fieldsobj.Items
Call doc.Replaceitemvalue(fieldname,Field.mGetItemValue("value")(0))
End ForAll
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?


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

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

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