How to upload attachment with Domino Data Services

I have tried the code below in an html file resource in Domino Designer, to upload an attachment to a new document in the current Domino database, whenever the user selects a file in the file upload control. There is no Domino form in the design of the database. The JavaScript file API is supported in my browser (Google Chrome Version 45.0.2454.99 m). I am using Domino Server 9.0.1.

A document is created, with a Body field containing MIME, and a $FILE field apparently containing the attached file. Yet when trying to download the file, the server finds no file. My link is like

attachment name

When I GET the document with Domino Data Services, the Body field has the binary content of the attachment corrupted. The multipart MIME structure of Body matches that of attachments created successfully by a Java agent.

It seems the binary data is being corrupted in transit to/from the server.

I have tried converting the binary data to a hexadecimal representation (as ASCII text) and converting back when read, but the input does not match the original. The same happened with Base64 encoding.

I have also tried using ‘processData: false’ in the jQuery Ajax call, to no avail.

I want to upload an attachment, which is correctly stored in $FILE, and can be downloaded from a web page with the link as above.

Please can anyone help me.

Upload

Subject: Content transfer encoding

Did you try specifying the content transfer encoding?

Base64 encoding is recommended – especially for binary data. You say you tried Base64 encoding, but did you also include the contentTransferEncoding property in your JSON input? I just tried the following POST request using the REST Client for Firefox. In my case, the {database} segment in the URL is just a mail file, but it should work for any type of database.

– Dave

POST /{database}/api/data/documents?form=Memo
Content-Type: application/json

{
“Subject”: “Sample file attachment”,
“Body”: {
“type”: “multipart”,
“content”: [
{
“contentType”: “application/octet-stream; name="file.dat"”,
“contentDisposition”: “attachment; filename="file.dat"”,
“contentTransferEncoding”: “base64”,
“data”: “UmFuZG9tIGZpbGUgZGF0YQ==”
}
]
}
}

Subject: I think the documentation stated that attachment would not be sent

At least that is what I remembered when reading it a few month ago.