2021-10-04 03:16 PM - last edited on 2021-10-05 08:46 PM by Laszlo Nagy
Hello everyone,
I am trying to upload file as multipart/form-data using clientconnection. But it failed.
This is my code.
void ExportIFC::ExportData(const char* buffer, UINT32 size)
{
using namespace HTTP::Client;
using namespace HTTP::MessageHeader;
using namespace HTTP::Encoding;
IO::URI::URI connectionUrl(LINKURL);
ClientConnection clientConnection(connectionUrl);
clientConnection.Connect();
GS::UniString url = "/upload/" + this->m_projectId + "/" + this->m_uploadHandle;
Request postRequest(Method::Post, url);
RequestHeaderFieldCollection& headers = postRequest.GetRequestHeaderFieldCollection();
GS::UniString bearer = "bearer " + this->m_token;
headers.Add(HeaderFieldName::Authorization, bearer);
headers.Add(HeaderFieldName::ContentType, "multipart/form-data");
headers.Add("Content-Disposition", "form-data; name=\"file\"; filename=\"test.ifc\"");
BodyOBinaryChannel& outChannel = clientConnection.BeginSend(postRequest);
outChannel.Write(buffer, size);
Response response;
clientConnection.Receive(response);
StatusCode::Id code = response.GetStatusCode();
if (code == StatusCode::OK)
{
// post process
}
}
clientConnection.FinishReceive();
clientConnection.Close(false);
}
What is my fault? Please help me.
2021-11-05 08:02 AM
Don't you need a clientConnection.FinishSend(); ?
2023-02-28 10:26 PM
Hey! Was you able to achieve this? I'm trying it too, with clientConnection.FinishSend(), but I'm getting some errors from the server, maybe due how I'm writing. Shouldn't boundaries be written?
2023-03-21 11:48 PM - edited 2023-03-21 11:49 PM
Hi,
I could not to upload the file with clientconnection.
So I solved the problem using cURL.
2023-03-27 02:37 AM - edited 2024-01-09 05:53 PM
Nice! I solved as well, but using libcpr (a curl wrapper that is very easy to use)