Dmytro Pastovenskyi
Dmytro Pastovenskyi

Reputation: 5419

Get Attachment from POST using Agent and LotusScript

I have a web form (see dummy example below), it's printed by an agent.

When form is submitted it's processed by an agent (LS).

I do not know how to retrieve files/attachments, that is my problem.

<form name="profile" method="POST" action=".../postAgentName?openagent">
<input name="title"/>
<input name="price"/>
...
<input type="file" name="files" multiple>
</form>

Attachments are not part of DocumentContext as far as I see but only file-names. I kind of suspect files could be temporary uploaded to Domino within request somewhere but really I'm not sure?

Is it possible to get attachments using LotusScript from "files" controller within agent written in LS? Can somebody point me in right direction? or maybe give a tip what should I do?

Thanks a lot.

Upvotes: 2

Views: 749

Answers (2)

andora
andora

Reputation: 1356

To accept files as part of form submission, you have to set the form 'enctype' attribute to handle files:

<form method="post" enctype="multipart/form-data" action="/x.nsf/x?CreateDocument" name="_fmForm">

Files attached using 'file upload control' (FUC) in Domino will be attached to the document and are accessible via attachment type embedded objects as part of the web-query-save event.

(Note: Generating your own form with a file-upload to Domino is tricky).

Upvotes: 0

Dmytro Pastovenskyi
Dmytro Pastovenskyi

Reputation: 5419

I have built my own solution

  1. when we select files on client side - we convert them to base64 with javascript
<form name="formName" method="post" action="agentName?openagent">
<input name="title" value="xxx">
<input type="file" name="files" multiple onchange="toBase64()">
</form>
  1. we add base64 strings to form just like normal so they will be submitted to endpoint (agent)

var reader = new FileReader();

  1. agent will get base64 value and convert it back to file (using LS or Java/LS2J)

Call stream.WriteText(base64File)

Call item.SetContentFromText(stream, contentType, ENC_BASE64)

See details here (could not format properly here): https://dpastov.blogspot.com/2021/01/how-to-post-attachments-using-form-to.html

Upvotes: 1

Related Questions