TWAIN ActiveX Control, Plug-in, Scanner SDK, Component, HTTP Control/SDK

Dynamsoft TWAIN Products

Support Community for TWAIN Control/Component/SDK for Scanning Solutions
* Login   * Register
* FAQ    * Search

It is currently Sun May 20, 2012 3:12 pm




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: HTTPUploadThroughPostEX saves invalid jpg files
PostPosted: Tue Jul 12, 2011 7:47 am 
Offline

Joined: Mon Mar 28, 2011 7:19 am
Posts: 4
When we create single-page jpgs by calling HTTPUploadThroughPost or HTTPUploadThroughPostEx, the file is saved with a jpg extension.

Windows Picture Viewer can open it, but Photoshop cannot open it.

The error is
"Could not complete your request because an unknown or invalid JPEG marker type is found"

If you view the file properties in Windows, you can see that the compression is set to CCITT T.6, which is a TIFF compression standard.

Any advice on where the problem is? I have related code snippets below:

CLIENT SIDE
Code:
WebTwain3.IfSSL = window.location.protocol == "https:";
   if (WebTwain3.IfSSL) {
      WebTwain3.HTTPPort = 443;
   }
   
   var docFormat = GetSettings("Format", "PDF");
   var docFileName = "ScannedDocument." + docFormat.toLowerCase();

   CopyToBufferForUpload();

   switch (docFormat) {
      case "JPG": WebTwain3.HTTPUploadThroughPostEx(strHostIP, 0, actionPage, docFileName, 1);
      case "TIFF": WebTwain3.HTTPUploadAllThroughPostAsMultiPageTIFF(strHostIP, actionPage, docFileName); break;
      case "PDF":
      default: WebTwain3.HTTPUploadAllThroughPostAsPDF(strHostIP, actionPage, docFileName); break;
   }

   CopyToBufferForReturn();

   if ((WebTwain3.HTTPPostResponseString).length > 0) {
      
      var queryString = WebTwain3.HTTPPostResponseString + "&nodeId=" + GetQueryString("nodeId", "0") + "&ImagesLeft=" + (WebTwain3.HowManyImagesInBuffer - LastPage.innerHTML);

      queryString += "&isQuickFinder=" + IsQuickFinder();
      var quickFinderMultipleIndex = GetQueryString("QuickFinderMultipleIndex", "0");

      queryString += "&QuickFinderMultipleIndex=" + quickFinderMultipleIndex;
      self.location = "../Add-Document.aspx" + queryString;
   }
   else {
      var errorMessage = WebTwain3.ErrorString.indexOf('Success') == 0 ? '' : WebTwain3.ErrorString;
      alert("There was a problem uploading your scanned file(s). Please try again. If the problem persists, contact support.\r\n" + errorMessage);
   }


SERVER SIDE (c#)
Code:
HttpFileCollection files = HttpContext.Current.Request.Files;
         HttpPostedFile uploadedFile = files["RemoteFile"];

         if (uploadedFile != null)
         {
            string temporaryPhysicalPath = HttpContext.Current.Server.MapPath("~" + ConfigurationManager.AppSettings["tempFileVirtualPath"]);
            string temporaryFileName = Guid.NewGuid().ToString() + System.IO.Path.GetExtension(uploadedFile.FileName);

            string contentType = "";
            switch (Path.GetExtension(uploadedFile.FileName).ToLower())
            {
               case ".tiff": contentType = "image/tiff"; break;
               case ".jpg": contentType = "image/jpeg"; break;
               case ".pdf":
               default: contentType = "application/pdf"; break;
            }            
            string response = string.Format("?TemporaryFileName={0}&ContentType={1}&DocumentSource=Scanner", context.Server.UrlEncode(temporaryFileName), context.Server.UrlEncode(contentType));
            uploadedFile.SaveAs(temporaryPhysicalPath + temporaryFileName);
            context.Response.ContentType = "text/plain";
            context.Response.Write(response);
         }


Top
 Profile  
 
 Post subject: Re: HTTPUploadThroughPostEX saves invalid jpg files
PostPosted: Tue Jul 12, 2011 9:15 pm 
Offline
User avatar

Joined: Tue Mar 08, 2005 12:23 am
Posts: 1075
Please try changing your server side code to:

Code:
<%@ Page Language="c#" AutoEventWireup="false" Debug="True"%>

<%
    HttpFileCollection files = HttpContext.Current.Request.Files;
    HttpPostedFile uploadfile  = files["RemoteFile"];
    uploadfile.SaveAs(System.Web.HttpContext.Current.Request.MapPath(".") + "/ImageScanned/" + uploadfile.FileName);
%>

If the problem persists, you can send your problematic JPEG file to twainsupport@dynamsoft.com. We'll check it for you.

_________________
Catherine Sea
TWAIN Support Team
TWAIN ActiveX/Plug-in for Web Applications, Scanner COM Control
TWAIN .NET Component/SDK for Desktop Applications

Follow me @Twitter, Facebook
Image


Top
 Profile  
 
 Post subject: Re: HTTPUploadThroughPostEX saves invalid jpg files
PostPosted: Wed Jul 13, 2011 7:58 am 
Offline

Joined: Mon Mar 28, 2011 7:19 am
Posts: 4
I think I figured it out.

We missed the "break" in the switch statement in the javascript. :oops:

So JPG and TIFF files were being saved using the HTTPUploadAllThroughPostAsMultiPageTIFF method


Top
 Profile  
 
 Post subject: Re: HTTPUploadThroughPostEX saves invalid jpg files
PostPosted: Thu Jul 14, 2011 12:40 am 
Offline
User avatar

Joined: Tue Mar 08, 2005 12:23 am
Posts: 1075
Glad to hear that you figured out the problem by yourself. :)

_________________
Catherine Sea
TWAIN Support Team
TWAIN ActiveX/Plug-in for Web Applications, Scanner COM Control
TWAIN .NET Component/SDK for Desktop Applications

Follow me @Twitter, Facebook
Image


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

It is currently Sun May 20, 2012 3:12 pm


Who is online

Users browsing this forum: EarnereapRirm and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron

Copyright © 2010 Dynamsoft Corporation. All Rights Reserved. | Knowledge Base | Source Control Blog