在lotus notes html表单中使用angularjs上传文件

File upload using angular js in lotus notes html form

我使用 Lotus Notes 形式作为 .html 文件,我使用 angular js 将值作为 json 发送到服务器。但我现在也想上传文件。如何将文件发送到服务器并使用 lotus 脚本提取?

你能帮帮我吗?

喜欢下面的post。但它是在 ASP.NET 中完成的。我想用莲花笔记做同样的事情。

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>

上面的按钮会触发下面的代码执行。

Angular 代码到 post 到服务器

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);

上面提到的代理(lotusscript)将解析上面的json并保存文档,如下所示。

ajaxprocess代理代码

'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

除文件附件外一切正常。如何使用 json 将文件发送到服务器并使用 Lotus 脚本保存,或者是否有任何其他解决方法?

终于找到了tip,解决方法如下,获取base64字符串,并在lotusscript中转换为attachment。

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)

这按预期工作。感谢大家抽出宝贵时间。

这是多附件的代码,来自 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