首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >动态Twain调用与React的集成

动态Twain调用与React的集成
EN

Stack Overflow用户
提问于 2022-10-27 09:13:00
回答 1查看 41关注 0票数 0

我正在使用动态Web在响应js中的应用。在用户扫描文档之后,本地保存文件可以正常工作,但我不知道要从动态Web向服务器发送什么样的文档数据。

我试过这个,

这是我的保存按钮逻辑。

代码语言:javascript
复制
  const saveOrUploadImage = (_type) => {
        if (_type !== "local" && _type !== "server") return;
        let fileName = saveFileName + "." + saveFileFormat;
        let imagesToUpload = [];
        let fileType = 0;
        let onSuccess = () => {
            setSaveFileName((new Date()).getTime().toString());
            imagesToUpload.push(props.buffer.current);

            _type === "local" ? props.handleOutPutMessage(fileName + " saved successfully!", "important") : props.handleOutPutMessage(fileName + " uploaded successfully!", "important");
        };
        let onFailure = (errorCode, errorString, httpResponse) => {
            (httpResponse && httpResponse !== "") ? props.handleOutPutMessage(httpResponse, "httpResponse") : props.handleException({ code: errorCode, message: errorString });
        };
        if (bMulti) {
            if (props.selected.length === 1 || props.selected.length === props.buffer.count) {
                if (_type === "local") {
                    switch (saveFileFormat) {
                        default: break;
                        case "tif": DWObject.SaveAllAsMultiPageTIFF(fileName, onSuccess, onFailure); break;
                        case "pdf": DWObject.SaveAllAsPDF(fileName, onSuccess, onFailure); break;
                    }
                }
                else {
                    for (let i = 0; i < props.buffer.count; i++)
                        imagesToUpload.push(i);
                }
            } else {
                if (_type === "local") {
                    switch (saveFileFormat) {
                        default: break;
                        case "tif": DWObject.SaveSelectedImagesAsMultiPageTIFF(fileName, onSuccess, onFailure); break;
                        case "pdf": {
                            DWObject.SaveAsPDF(fileName, props.buffer.current, onSuccess, onFailure)
                            console.log('GetImageURL', Dynamsoft.DWT.GetImageURL(props.buffer.current));
                            console.log("DWObject.SaveAllAsPDF()---", DWObject.SaveAllAsPDF(fileName, props.buffer.current, onSuccess, onFailure));
                            console.log("DWObject---", DWObject);
                            DWObject.SaveSelectedImagesAsMultiPagePDF(fileName, onSuccess, onFailure)
                        }; break;
                    }
                }
                else {
                    imagesToUpload = props.selected;
                }
            }
        } else {
            if (_type === "local") {
                switch (saveFileFormat) {
                    default: break;
                    case "bmp": DWObject.SaveAsBMP(fileName, props.buffer.current, onSuccess, onFailure); break;
                    case "jpg": DWObject.SaveAsJPEG(fileName, props.buffer.current, onSuccess, onFailure); break;
                    case "tif": DWObject.SaveAsTIFF(fileName, props.buffer.current, onSuccess, onFailure); break;
                    case "png": DWObject.SaveAsPNG(fileName, props.buffer.current, onSuccess, onFailure); break;
                    case "pdf": {
                        DWObject.SaveAsPDF(fileName, props.buffer.current, onSuccess, onFailure)      
                    }; break;
                }
               imagesToUpload.push(props.buffer.current);
               console.log("props.buffer.current", props.buffer.current); //0
            }
           
        }
        for (let o in Dynamsoft.DWT.EnumDWT_ImageType) {
        
            if (o.toLowerCase().indexOf(saveFileFormat) !== -1 && Dynamsoft.DWT.EnumDWT_ImageType[o] < 7) {
                fileType = Dynamsoft.DWT.EnumDWT_ImageType[o];
                break;
            }
        }
  }

我正在跟踪这个GitHub存储库。GitHub链路

如果你知道这个问题的答案,请告诉我该怎么做。

EN

回答 1

Stack Overflow用户

发布于 2022-11-01 08:50:03

上载文件的步骤:

  1. 初始化文件上传器: Dynamsoft.FileUploader.Init("",(objFileUploader) => { fileUploaderManager = objFileUploader;if (! fileUploaderReady ) {fileUploaderReady= true;props.handleStatusChange(128);},(errorCode,errorString) => { props.handleException({ code: errorCode,message: errorString });if (! fileUploaderReady ) {fileUploaderReady= true;props.handleStatusChange(128);};
  2. 配置目标文件,包括文件名和文件类型: 让协议= Dynamsoft.Lib.detect.ssl?Https://“:http://”let _strPort = 2020;strActionPage = "/upload";serverUrl = protocol + window.location.hostname +:“+ _strPort + strActionPage;if (bUseFileUploader) { var _strPort= fileUploaderManager.CreateJob();job.ServerUrl = serverUrl;job.FileName = fileName;job.ImageType = fileType;DWObject.GenerateURLForUploadData(imagesToUpload,fileType,(resultURL,newIndices,enumImageType) => { job.SourceValue.Add(resultURL,fileName);job.OnUploadTransferPercentage = (job,sPercentage) => {props.handleOutPutMessage(“上载.(+ sPercentage +%)”);};job.OnRunSuccess = (job) => { onSuccess() };job.OnRunFailure = (job,errorCode,errorString) => onFailure(errorCode,errorString);fileUploaderManager.Run(job);},(errorCode,errorString,strHTTPPostResponseString,newIndices,enumImageType) => { props.handleException({ code: errorCode,message: errorString });};}
  3. 将文件上载到服务器。 DWObject.GenerateURLForUploadData(imagesToUpload,fileType,(resultURL,newIndices,enumImageType) => { job.SourceValue.Add(resultURL,fileName);job.OnUploadTransferPercentage = (job,sPercentage) => {props.handleOutPutMessage(“上载.(+ sPercentage +%)”);};job.OnRunSuccess = (job) => { onSuccess() };job.OnRunFailure = (job,errorCode,errorString) => onFailure(errorCode,errorString);fileUploaderManager.Run(job);},(errorCode,errorString,strHTTPPostResponseString,newIndices,enumImageType) => { props.handleException({ code: errorCode,message: errorString });};

除了文件上传器之外,您还可以调用HTTPUpload()方法:

代码语言:javascript
复制
DWObject.HTTPUpload(serverUrl, imagesToUpload, fileType, Dynamsoft.DWT.EnumDWT_UploadDataFormat.Binary, fileName, onSuccess, onFailure);
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/74219525

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档