Skip to main content

Add Multipart file

Adds a file block to the multipart/form-data body

Function AddMultipartFormDataFile(Val FieldName, Val FileName, Val Data, Val DataType = "") Export

ParameterCLI optionTypeRequiredDescription
FieldName-StringForm field name
FileName-StringFile name with extension
Data-BinaryData, StringFile data to be written
DataType-StringMIME type of data

Returns: DataProcessorObject.OPI_HTTPClient - This processor object


tip

The Multipart record must first be initialized using the StartMultipartBody function

Parameters with Binary data type can also accept file paths on disk and URLs

caution

NOCLI: this method is not available in CLI version


1C:Enterprise/OneScript code example
    URL = "https://httpbin.org";
URL = URL + "/post";

Image = "https://api.athenaeum.digital/test_data/picture.jpg"; // URL, Path or Binary Data

Result = OPI_HTTPRequests.NewRequest()
.Initialize(URL)
.StartMultipartBody()
.AddMultipartFormDataFile("file1", "pic.png", Image, "image/png") // <---
.AddMultipartFormDataField("Field1", "Text")
.AddMultipartFormDataField("Field2", "10")
.ProcessRequest("POST")
.ReturnResponseAsJSONObject();
Result
{
"args": {},
"data": "",
"files": {
"file1": "..."
},
"form": {
"Field1": "Text",
"Field2": "10"
},
"headers": {
"Accept": "*/*",
"Accept-Charset": "utf-8",
"Accept-Encoding": "gzip",
"Content-Length": "2114372",
"Content-Type": "multipart/form-data; boundary=1b4d6ff7f757440ebce8b80f70c04584",
"Host": "httpbin.org",
"User-Agent": "1Script v$1.9.2.10",
"X-Amzn-Trace-Id": "Root=1-682cd6be-3c74b8a70273b27e7aece353"
},
"json": null,
"origin": "***",
"url": "https://httpbin.org/post"
}