|
|
@@ -0,0 +1,68 @@
|
|
|
+Dynamsoft.DWT.RegisterEvent('OnWebTwainReady', Dynamsoft_OnReady);
|
|
|
+var DWObject;
|
|
|
+function Dynamsoft_OnReady() {
|
|
|
+ DWObject = Dynamsoft.DWT.GetWebTwain('dwtcontrolContainer');
|
|
|
+}
|
|
|
+
|
|
|
+function AcquireImage() {
|
|
|
+ if (DWObject) {
|
|
|
+ DWObject.SelectSource(function () {
|
|
|
+ var OnAcquireImageSuccess, OnAcquireImageFailure;
|
|
|
+
|
|
|
+ OnAcquireImageSuccess = OnAcquireImageFailure = function () {
|
|
|
+ UploadImage()
|
|
|
+ console.log(DWObject.CurrentImageIndexInBuffer)
|
|
|
+ DWObject.CloseSource();
|
|
|
+ };
|
|
|
+
|
|
|
+ DWObject.OpenSource();
|
|
|
+
|
|
|
+ DWObject.IfFeederEnabled = false
|
|
|
+ DWObject.IfShowUI = false; //Disable scanner UI.
|
|
|
+ DWObject.IfDisableSourceAfterAcquire = true;//Scanner source will be disabled automatically after scan.
|
|
|
+
|
|
|
+ // if (document.getElementById("ADF").checked && DWObject.IfFeederEnabled == true) // if paper is NOT loaded on the feeder
|
|
|
+ if (DWObject.IfFeederEnabled && DWObject.IfFeederEnabled == true)
|
|
|
+ {
|
|
|
+ if (DWObject.IfFeederLoaded != true && DWObject.ErrorCode == 0) {
|
|
|
+ alert("No paper detected! Please load papers and try again!");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ DWObject.AcquireImage(OnAcquireImageSuccess, OnAcquireImageFailure);
|
|
|
+ }, function () {
|
|
|
+ console.log('SelectSource failed!');
|
|
|
+ });
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+function UploadImage() {
|
|
|
+ if (DWObject) {
|
|
|
+ // If no image in buffer, return the function
|
|
|
+ if (DWObject.HowManyImagesInBuffer == 0)
|
|
|
+ return;
|
|
|
+
|
|
|
+ var strHTTPServer = location.hostname; //The name of the HTTP server. For example: "www.dynamsoft.com";
|
|
|
+ var CurrentPathName = unescape(location.pathname);
|
|
|
+ var CurrentPath = CurrentPathName.substring(0, CurrentPathName.lastIndexOf("/") + 1);
|
|
|
+ var strActionPage = CurrentPath + "SaveToFile.aspx";
|
|
|
+
|
|
|
+ var strHTTPServer = "118.190.145.217"
|
|
|
+ var strActionPage = "/api/admin/uploadfile"
|
|
|
+ DWObject.IfSSL = false; // Set whether SSL is used
|
|
|
+ DWObject.HTTPPort = 8000//location.port == "" ? 80 : location.port;
|
|
|
+
|
|
|
+ var Digital = new Date();
|
|
|
+ var uploadfilename = Digital.getMilliseconds(); // Uses milliseconds according to local time as the file name
|
|
|
+ DWObject.HTTPUploadThroughPost(strHTTPServer, DWObject.CurrentImageIndexInBuffer, strActionPage, uploadfilename + ".jpg", OnHttpUploadSuccess, OnHttpUploadFailure);
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+function OnHttpUploadSuccess() {
|
|
|
+ console.log('successful');
|
|
|
+}
|
|
|
+
|
|
|
+function OnHttpUploadFailure(errorCode, errorString, sHttpResponse) {
|
|
|
+ alert(errorString + sHttpResponse);
|
|
|
+}
|