Continuing with the discussion, testing the HTTP POST Request - Multipart example from here, from the same page that @Jon posted above:
curl --location 'https://echo.free.beeceptor.com/' --form 'action="form-submit"' --form 'file=@"sample_file.jpg"'
The output is:
{
"method": "POST",
"path": "/",
"ip": "136.185.41.120",
"headers": {
"host": "echo.free.beeceptor.com",
"user-agent": "curl/7.88.1",
"content-length": "55561",
"accept": "*/*",
"accept-encoding": "gzip, deflate, br",
"content-type": "multipart/form-data; boundary=--------------------------362521674601421993043015"
},
"parsedQueryParams": { },
"parsedBody": {
"textFields": {
"action": "form-submit"
},
"files": [
{
"name": "file",
"fileName": "sample_file.jpg",
"contentType": "image/jpeg"
}
]
}
}
The same example in DOpus:
function OnClick(clickData)
{
DOpus.ClearOutput();
if (!clickData.func.sourcetab.stats.selfiles) return;
var item = clickData.func.sourcetab.selected_files(0);
if (item.size == 0) return;
DOpus.Output("item : " + item);
var Dlg = DOpus.Dlg;
Dlg.window = clickData.func.sourcetab;
Dlg.template = "testdlg";
Dlg.detach = true;
Dlg.Show();
var newReq = Dlg.NewHTTPReq();
var blob = DOpus.Create.Blob();
blob.CopyFrom(item.Open.Read());
DOpus.Output("file size : " + item.size);
DOpus.Output("blob size : " + blob.size);
newReq.AddPostData("action", "formsubmit");
newReq.AddPostData("file",blob);
newReq.SendRequest("https://echo.free.beeceptor.com");
while (true)
{
var Msg = Dlg.GetMsg();
if (!Msg.result) break;
if (Msg.event == "http" && !newReq.complete)
{
if (Msg.value == "data")
{
var reqData = newReq.ReadResponse();
DOpus.SetClip(reqData);
newReq.shutdown();
}
else if (Msg.value == "error")
{
var headers = newReq.GetResponseHeaders();
for (var hdr = new Enumerator(headers); !hdr.atEnd(); hdr.moveNext())
{
DOpus.Output(hdr.item() + ": " + headers(hdr.item()));
}
}
else DOpus.Output(Msg.value);
}
}
}
The response:
{
"method": "POST",
"protocol": "https",
"host": "echo.free.beeceptor.com",
"path": "/",
"ip": "xxxxxxxxxx",
"headers": {
"Host": "echo.free.beeceptor.com",
"User-Agent": "Mozilla/4.0",
"Content-Length": "90840",
"Accept": "*/*",
"Accept-Encoding": "identity",
"Accept-Language": "en-us",
"Content-Type": "multipart/form-data, boundary=__DOPUS__xXxXxXxX__"
},
"parsedQueryParams": {},
"parsedBody": {
"textFields": {
"action": "formsubmit",
"file": "/9j/4AAQSkZJRgABAQAAAQABAAD/4gIYSUNDX1BST0ZJTEUAAQEAAAIIAAAAAAQwAABtbnRyUkdC..."
},
"files": []
}
}
So it would seem that the uploaded files are not in the correct location (files), but rather in the values treated as text (textFields).
Any comment about this?