Uploads the image of a specified index in buffer to the HTTP server as a specified image format through HTTP POST method.
Boolean ObjectName. HTTPUploadThroughPostEx(String HTTPServer, Short sImageIndex, String ActionPage, String FileName, Long ImageType)
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.
Long ImageType: the image format of the file to be created on the HTTP server.
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.
Dynamic Web TWAIN processes the image format according to the value of the ImageType.
| Allowed Values | ImageType |
| 0 | BMP |
| 1 | JPEG |
| 2 | TIFF |
| 3 | PNG |
| 4 |
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>".
FTPUserName property, FTPPassword property, FTPPort property, ProxyServer property, FTPDownloadEx(), HTTPPort property, HTTPUserName property, HTTPPassword property, HTTPDownloadEx(), HTTPUploadThroughPutEx(), HTTPUploadThroughPostEx()
A simple JSP 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
JSP Sample:
Snippet in Scan.jsp:
...
<script language="javascript">
function btnScan_onclick()
{
frmScan.DynamicWebTwain1.SelectSource();
frmScan.DynamicWebTwain1.AcquireImage();
}
function btnUpload_onclick()
{
var strActionPage;
var strHostIP;
var CurrentPathName = unescape(location.pathname); // get current PathName in plain ASCII
var CurrentPath = CurrentPathName.substring(0, CurrentPathName.lastIndexOf("/") + 1);
strActionPage = CurrentPath + "SaveToFile.jsp"; //the ActionPage's file path
frmScan.DynamicWebTwain1.HTTPPort = 80;
frmScan.DynamicWebTwain1.HTTPUploadThroughPostEx("127.0.0.1", 0, strActionPage, "imageData.jpg", 1);
if (frmScan.DynamicWebTwain1.ErrorCode != 0)
//alert(frmScan.DynamicWebTwain1.ErrorString);
alert(frmScan.DynamicWebTwain1.HTTPPostResponseString);
else //succeded
}
</script>
...
|
SaveToFile.jsp:
<%@ page language="java" import="java.io.*"%> <%
String contentType = request.getContentType();
if ((contentType != null) && (contentType.indexOf("multipart/form-data") >= 0))
{
DataInputStream in = new DataInputStream(request.getInputStream());
int formDataLength = request.getContentLength();
byte dataBytes[] = new byte[formDataLength];
int byteRead = 0;
int totalBytesRead = 0;
while (totalBytesRead < formDataLength)
{
byteRead = in.read(dataBytes, totalBytesRead, formDataLength);
totalBytesRead += byteRead;
}
in.close();
String file = new String(dataBytes);
String saveFile = file.substring(file.indexOf("filename=\"") + 10);
saveFile = saveFile.substring(0, saveFile.indexOf("\n"));
saveFile = saveFile.substring(saveFile.lastIndexOf("\\") + 1,saveFile.indexOf("\""));
int lastIndex = contentType.lastIndexOf("=");
String boundary = contentType.substring(lastIndex + 1, contentType.length());
int pos;
pos = file.indexOf("filename=\"");
pos = file.indexOf("\n", pos) + 1;
pos = file.indexOf("\n", pos) + 1;
pos = file.indexOf("\n", pos) + 1;
int boundaryLocation = file.indexOf(boundary, pos) - 4;
int startPos = ((file.substring(0, pos)).getBytes()).length;
int endPos = ((file.substring(0, boundaryLocation)).getBytes()).length;
File fileToRecv = new File(application.getRealPath("/") + saveFile);
if(!fileToRecv.exists())
{
fileToRecv.createNewFile();
}
FileOutputStream fileOut = new FileOutputStream(fileToRecv);
fileOut.write(dataBytes, startPos, (endPos - startPos));
fileOut.flush();
fileOut.close();
}
%>
|
TWAIN ActiveX | TWAIN Plug-in | TWAIN Control | TWAIN SDK | Scanner COM
Software Configuration Management | Version Control | Source Control
Copyright © 2011 Dynamsoft Corporation. All Rights Reserved.