Lotusscript:使用 PHP 将文件从电子邮件发送到网站的问题

问题描述

我想通过 lotusscript 代理将我当前电子邮件中的文件发送到我的网站。我想做这样的事情:(我知道这段代码不能工作,但它是为了展示这个想法)

Sub Initialize
    On Error GoTo ErrorHandler
    Dim session As New NotesSession
    Dim db As NotesDatabase
    Dim doc As Notesdocument
    Dim item As Variant
    Dim uidoc As NotesUIDocument
    Dim CurrentDocColl As NotesdocumentCollection
    Dim url As String
    Dim jsonBody As String
    Dim http As NotesHTTPRequest
    Dim headers As Variant
    Dim ret As Variant

    Set Session = New NotesSession
    Set db = Session.Currentdatabase
    Set CurrentDocColl = db.Unprocesseddocuments 
    Set doc = CurrentDocColl.Getfirstdocument
    While Not doc Is nothing
        Set item = doc.GETFirsTITEM("Body")
        If doc.HasEmbedded Then
            url="http://myurl.com/addFiles.PHP"
            jsonBody="value={""id"":""7777"",""file"":"""+item.Embeddedobjects+"""}"

            Set http=session.CreateHTTPRequest()
            http.preferstrings = True

            Call http.SetHeaderField("ContentType","application/json")

            ret = http.Post(url,jsonBody)
            MessageBox ret
        End If
        Set doc=CurrentDocColl.Getnextdocument(doc)
    Wend
    
    Exit Sub
ErrorHandler:  
    MessageBox "Erreur N° : " +Cstr(Err)_    ' code numérique de l'erreur  
    +" Description : " + Error(Err)_      ' La description de l'erreur 
    + " Ligne N° : "+ CStr(Erl)_   ' La ligne où se trouve l'erreur 
    +"",16," ERREUR !" 
    Exit Sub
End Sub

这是我用来检索文件PHP 代码

header("vary: Origin");
header("Content-type: application/json");

if (isset($_FILES['file'])) {
    $total = count($_FILES['file']['name']);
    for ($i = 0; $i < $total; $i++) {
        $tmpFileName = $_FILES['file']['tmp_name'][$i];
        echo $tmpFileName;
    }
}

如何将他的文件发送到我的网站?因为通常在 Javascript 中,当我们想要将文件发送到 PHP 代码时,我们将其发送到包含“文件”类型字段的 FormData 中。但我不知道 lotusscript 中的等价物。我对如何做到这一点有点困惑。 感谢您的帮助!

解决方法

您将需要使用 ExtractFile 类的 NotesEmbeddedObject 方法将附件数据保存到文件中,然后您将需要读取文件的内容并将其放入您为 POST 数据发送的变量中。据我所知,一步完成这件事没有捷径。我使用这种技术已经有好几年了,它是用 Java 代码而不是 LotusScript 编写的。请注意,您的代码必须具有在运行代码的服务器或客户端上创建文件的权限。