2
votes

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?

2
What have you tried? Show us the code you have written to attempt this and tell uw what happened.Richard Schwartz
Hi Richard,Thanks for the response. I have edited the post. Please have a look.Vijayakumar
Your Angular code references an agent called ajaxprocess. Where is that agent? Show the source code you have tried.Richard Schwartz
I have posted server code above. Now I am sending all the field types (text,date,time) and able to save the document. But I am not able to achieve file upload using the above code, since I dont know the method to upload and decode the attachments. Please let me know if it is not clear. Thank you for your precious time for helping me. very much appreciated.Vijayakumar
I'm afraid I can't help with what you need to do on the browser side with angular.js. I do know that if you want to actually store it so that it will be seen by Domino as an attachment, you'll have to do more processing in your LotusScript code - but if it's not even uploading for you that's not relevant. I've upvoted the question, and maybe someone who knows angular will be able to assist.Richard Schwartz

2 Answers

2
votes

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.

2
votes

Here is the code for Multiple attachments, enhancement from Vijayakumar.

Dim session As New NotesSession
    Dim db As NotesDatabase
    Dim doc As NotesDocument
    Set db = session.CurrentDatabase
    Set doc = db.CreateDocument
    Dim s As New NotesSession
    Dim stream As NotesStream   
    Dim body As NotesMIMEEntity
    Dim child As NotesMimeEntity
    Dim header As NotesMIMEHeader
    Set body =  doc.CreateMIMEEntity


    topString = Split(BASE64, ",")

    Dim tmp_array() As String
    i = 0

    For i = 0 To Ubound(topString)
        Redim Preserve tmp_array(i)
        tmp_array(i) = topString(i)


        Set child = body.CreateChildEntity()
        Set header = child.CreateHeader("Content-Type")
        Call header.SetHeaderVal("multipart/mixed") 
        Set header =child.createHeader("Content-Disposition")
        Call header.setHeaderVal({attachment; filename=test} &Cstr(i)& {.jpg}) 'file name and type should be configure


        Set header =child.CreateHeader("Content-ID")
        Call header.SetHeaderVal("test" &Cstr(i)& ".jpg")

        Set stream = s.CreateStream()
        Call stream.WriteText(topString(i))
        Call child.SetContentFromText(stream, "", ENC_BASE64)

    Next

    doc.form="Attachment"
    'doc.Attachment = tmp_array 
    Call doc.save(True,False)
    Call stream.Close() 
    s.ConvertMIME = True ' Restore conversion