Skip to content

Instantly share code, notes, and snippets.

@Kuranes
Last active December 29, 2015 02:19
Show Gist options
  • Save Kuranes/7600008 to your computer and use it in GitHub Desktop.
Save Kuranes/7600008 to your computer and use it in GitHub Desktop.
simple upload from c++ code using microsoft windows WININET library, and code project http code simplification wrapper
#include "HTTP_client.h" //http://www.codeproject.com/Articles/3849/Simple-HTTP-Client-using-WININET
#include <iostream>
int _tmain(int argc, _TCHAR* argv[])
{
HTTP_client *pClient = new HTTP_client();
pClient->InitilizePostArguments();
// if using utf-8 characters in your Post Arguments
// be sure to save source code file as utf-8
// Visual Studio => File menu => "advanced save option" => encoding => "Unicode (UTF-8 without signature) - Codepage 65001"
pClient->AddPostArguments( "token", "p76ab7dcc3149badbd24983fd5fddf3f" );// token from sketchfab user dashboard
pClient->AddPostArguments( "fileModel", "C:\\mymodelfiles.zip", TRUE ); // file path
pClient->AddPostArguments( "title", "nice model title" );
//pClient->AddPostArguments( "description", "fitting description" );
//pClient->AddPostArguments( "tags", "meaningfultag moremeaningfultag" );
//pClient->AddPostArguments( "private", "1" );// "0" or not
//pClient->AddPostArguments( "password", "myprivatepass" );
if( pClient->Request( _T("https://api.sketchfab.com/v1/models"), HTTP_client::RequestPostMethodMultiPartsFormData, _T( "CppUploader" ) ) )
{
std::cout << pClient->QueryHTTPResponse() << std::endl; // server response as json read it for succesfull or not upload
std::cout << "\n" << std::endl;
std::cout << pClient->QueryHTTPResponseHeader() << std::endl;
}
else{
std::cout << "connection fail\n" << std::endl;// something failed, network related you didn't reach sketchfab server
}
if( pClient )
{
delete pClient;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment