Quote:
Originally Posted by KyleS
Can't you just set the headers?
|
Yes but how I still connected to the host?
I can't send 70mb file with SteamWorks_SetHTTPRequestRawPostBody at one.
Now i split and send multipart like real multipart will do.
EDIT:
I forgot to post a sample code... now I'm doing a fake multipart (with redis in the server i handle the parts)
the idea is to use the multipart protocol
Code:
#include <sourcemod>
#include <SteamWorks>
public Plugin myinfo =
{
name = "MultiPart",
author = "Ramón Berrutti <Reymon>",
description = "MultiPart test",
version = "1.0",
url = "https://ramonberrutti.com"
};
public void OnPluginStart()
{
RegServerCmd("multipart_test", OnConsole_multipart_test, "Test MultiPart");
}
public Action OnConsole_multipart_test(int args)
{
File file = OpenFile("ebacon2__round06.txt", "r");
UploadFile( file );
return Plugin_Handled;
}
void UploadFile(File file)
{
if( file.EndOfFile() )
{
file.Close();
return;
}
char buffer[1024];
if(!file.EndOfFile() && file.ReadString(buffer, sizeof(buffer)))
{
Handle req = SteamWorks_CreateHTTPRequest( k_EHTTPMethodPOST, "http://localhost:3000/api/backups");
SteamWorks_SetHTTPCallbacks(req, RequestCallback);
SteamWorks_SetHTTPRequestContextValue(req, file);
char buffer2[2048];
FormatEx(buffer2, sizeof(buffer2), "--%s\r\nContent-Disposition: form-data; name=\"file\"; filename=\"test.txt\"\r\nContent-Type: text/plain\r\n\r\n%s", "AaB03x", buffer);
// If file finish add the finish part
/*if( file.EndOfFile() )
{
Format(buffer2, sizeof(buffer2), "%s\r\n--%s--", buffer2, "AaB03x");
}*/
Format(buffer2, sizeof(buffer2), "%s\r\n--%s--", buffer2, "AaB03x");
PrintToServer("New Part Size:%i -->\n%s", strlen(buffer2), buffer2);
SteamWorks_SetHTTPRequestRawPostBody(req, "multipart/form-data; boundary=AaB03x", buffer2, strlen(buffer2));
SteamWorks_SendHTTPRequest(req);
}
}
public int RequestCallback(Handle request, bool failure, bool requestSuccessful, EHTTPStatusCode statusCode, File file)
{
//PrintToServer("%i) Failure: %i RquestSuccessful: %i Status: %i", count, failure, requestSuccessful, statusCode);
if( requestSuccessful && statusCode == k_EHTTPStatusCode200OK )
{
UploadFile(file);
}
}