Developer forum
cancel
Showing results for 
Search instead for 
Did you mean: 

How to post file using api.

Chris Howell
Participant

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.

 

1 REPLY 1

dushyant
Booster

Don't you need a clientConnection.FinishSend(); ?

Still looking?

Browse more topics

Back to forum

See latest solutions

Accepted solutions

Start a new discussion!