Dynamsoft Home|Product Home

HTTPUploadThroughPost Method

Description

Uploads the image of a specified index in buffer to the HTTP server through HTTP POST method.

Syntax

Boolean ObjectName. HTTPUploadThroughPost(String HTTPServer, Short sImageIndex, String ActionPage, String FileName)

Parameters

String HTTPServer: the name of the HTTP server.

Short sImageIndex: specifies the index of image in buffer. The index is 0-based. 

String ActionPage: the specified page for posting image files. This is the relative path of the page, not the absolute path. For example: "upload.asp", not "http://www.webserver.com/upload.asp". This is the page corresponds to the action in <form> html tag: <form id = "frmSample" action = "upload.asp" method = post>...</form>

String FileName: the name of the image to be uploaded.

Return value

Boolean.

TRUE indicates success. FALSE indicates failure.

When an error occurs and IfThrowException property is TRUE, an exception will be thrown.

When FALSE is returned or an exception is thrown, check ErrorCode property and ErrorString property for error information.

Remarks

Dynamic Web TWAIN processes the image format according to the extension of the FileName.

Dynamic Web TWAIN supports the following types of image files:

Bitmap *.bmp, *.dib
JPEG *.JPG, *.JPEG, .*.JPE, *.JFIF
TIFF *.TIF, *.TIFF
PNG *.PNG
PDF *.PDF

The field name of the uploaded image is RemoteFile.

IMPORTANT: Dynamic Web TWAIN uses a special way to see if an image is uploaded and processed successfully by server. If the server returns 0 bytes, indicates success. Otherwise, indicates failure. In other words, when the uploaded image is processed successfully, the action page on the server should not return anything, even the "<HTML>".

See also

FTPUserName property, FTPPassword property, FTPPort property, ProxyServer property, FTPDownload(), FTPUpload(), HTTPPort property, IfSSL property, HTTPUserName property, HTTPPassword property, HTTPDownload(),, HTTPUploadThroughPut()

Sample

A simple PHP sample is provided. Should you need sample in other languages, please access the following page to download samples.
https://www.dynamsoft.com/Secure/RegisterInfo_sample.aspx

PHP Sample:

Snippet in Scan.php:
...

<script language="javascript">

function btnScan_onclick() {
	frmScan.DynamicWebTwain1.SelectSource();
	frmScan.DynamicWebTwain1.AcquireImage();
}

function btnUpload_onclick() {

	frmScan.DynamicWebTwain1.HTTPPort = 80; // if 80 is the port number of non-secure port
	frmScan.DynamicWebTwain1.IfSSL = false;
	frmScan.DynamicWebTwain1.HTTPUploadThroughPost("127.0.0.1", 0, "/SaveToFile.php", "imageData.jpg");

	if (frmScan.DynamicWebTwain1.ErrorCode != 0)
		alert(frmScan.DynamicWebTwain1.ErrorString);
	else //succeded
		alert("Successful");
}

</script>

...

SaveToFile.php:
<?	
	$fileTempName = $_FILES['RemoteFile']['tmp_name'];	
	$fileSize = $_FILES['RemoteFile']['size'];
	$fileName = $_FILES['RemoteFile']['name'];

	if (file_exists($fileName)) 
		$fWriteHandle = fopen($fileName, 'w');
	else
		$fWriteHandle = fopen($fileName, 'x');

	$fReadHandle = fopen($fileTempName, 'rb');

	$fileContent = fread($fReadHandle, $fileSize);

	fwrite($fWriteHandle, $fileContent);

	fclose($fWriteHandle);
?>