Up

_networkSetHTTPput

Upload a file from an HTTP PUT request.

Prototype :

fun [ObjNetwork S P] ObjNetwork

Return : ObjNetwork the same object or nil if an error occurs. In this last case, _networkGetError gives you informations.

See also :

_networkSetHTTPpost

_networkGetError

_networkSetOption

Example :

Upload the logo of Scol to a server in the no-threaded mode. Two optionals callbacks are defined :

  1. _networkCBverbose;
  2. _networkCBread.

fun cbVerbose (obj, user_parameter, type, message)=
	_fooS sprintf "Type = >>>>> %d\n%s" [type message];
	0;;
	
fun cbRead (obj, user_parameter, read, asked)=
	_fooS "Read .......";
	_fooId read;
	_fooId asked;
	0;;
	
fun goFunsPackage ()=
	_networkSetMode Net NETWORK_NOTHREADED;
	_networkCBverbose Net @cbVerbose 0;
	_networkCBread Net @cbRead 0;
	if (nil == _networkSetHTTPput Net "http://www.domain.tld/folder/script_put.php" _checkpack "logo.bmp")
	(
		_fooS "An error is occured !";
		_fooS sprintf "error number : %d error string %s" _networkGetError Net;
		1
	)
	else
	(
		_networkPerform Net;
		_fooS sprintf "AFTER PERFORM : error number : %d error string %s" _networkGetError Net;
		0
	);;

fun upload ()=
	let _networkLoaded -> res in
	(
		_fooS strcat "Network library loaded ? " itoa res;
		if res then
		(
			set Net = _networkCreate _channel;
			if (Net == nil) then
			(
				_fooS "Object not created";
				1
			)
			else
				goFunsPackage;
		)
		else
			1;
	);;
	
fun main ()=
	_showconsole;
	_fooS strcat "Result = " itoa upload;	// 0 = success
	0;;

You could have on your server something like that (in PHP in this example) :

<?php
$putdata = fopen ("php://input", "r");

$fp = fopen ("logo.bmp", "w");

while ($data = fread ($putdata, 1024))
	fwrite ($fp, $data);

fclose ($fp);
fclose ($putdata);
?>

Note :

Don't forget to give enough rights on the server script and, if any, configure your server to accept a PUT request. By example, you can read this web page : http://www.apacheweek.com/features/put, if the server runs under Apache.