【问题标题】:File upload using angular js in lotus notes html form在 Lotus Notes html 表单中使用 Angular js 上传文件
【发布时间】:2015-05-12 08:32:47
【问题描述】:

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

你能帮帮我吗?

喜欢下面的帖子。但它是在 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 代码

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

上面提到的agent(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 脚本保存或是否有其他解决方法?

【问题讨论】:

  • 你试过什么?向我们展示你编写的代码来尝试这个并告诉你发生了什么。
  • 嗨,理查德,感谢您的回复。我已经编辑了帖子。请看一看。
  • 您的 Angular 代码引用了一个名为 ajaxprocess 的代理。那个代理在哪里?显示您尝试过的源代码。
  • 我已经在上面发布了服务器代码。现在我正在发送所有字段类型(文本、日期、时间)并能够保存文档。但是我无法使用上面的代码实现文件上传,因为我不知道上传和解码附件的方法。如果不清楚,请告诉我。感谢您宝贵的时间帮助我。非常感谢。
  • 恐怕我无法帮助您使用 angular.js 在浏览器端做些什么。我确实知道,如果您想实际存储它以便 Domino 将其视为附件,您将不得不在您的 LotusScript 代码中进行更多处理 - 但如果它甚至没有为您上传,那是不相关的。我已经对这个问题投了赞成票,也许知道 Angular 的人可以提供帮助。

标签: json angularjs file-upload lotus-notes lotusscript


【解决方案1】:

我终于找到了tip,做了如下的解决方案,获取base64字符串并在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)

这按预期工作。感谢大家花费的时间。

【讨论】:

    【解决方案2】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多