Raised This Month: $403 Target: $400
 100% 

[ANY] SteamWorks


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
ReymonARG
Junior Member
Join Date: Jun 2017
Old 09-26-2017 , 16:46   Re: [ANY] SteamWorks
Reply With Quote #11

Quote:
Originally Posted by KyleS View Post
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);
	}
}

Last edited by ReymonARG; 09-26-2017 at 17:52.
ReymonARG is offline
 


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 10:19.


Powered by vBulletin®
Copyright ©2000 - 2018, vBulletin Solutions, Inc.
Theme made by Freecode