在这个话题▼< / div >< div id ="inThisTopicDialog" class="hide">

还是方法

总结< / div >

上传一个新文档到服务器一箭。

语法< / div >< div id ="mainSourceContainerSyntax">
打印稿< / div >
JavaScript< / div >< / div >
还是=函数(,documentId)
静态还是(:团,documentId:字符串):AbortableJqueryPromise;

参数

JavaScript/文件对象代表了文件上传。

documentId

可选:ID用于加载文档。

返回值

一个承诺对象,可以成功地解决特殊uri指向新创建的位置LEADDocument在缓存中(可查IsUploadDocumentUri)。返回的承诺有一个独特的类型的AbortableJQueryPromise保存中止方法。

讲话< / div >

UploadFileDocument执行相同的功能还是在接受全UploadDocumentOptions选择上传的更多的控制操作。

时的值documentId(默认),然后工厂将创建一个新的文档,使用GUID发生器惟一的ID。如果该值不是,那么它被假定为一个用户定义的ID和使用。在这两种情况下,该值设置LEADDocument.DocumentId新创建的文档的属性。

可以使用用户定义的id当系统已经有独特的id相关联的文档查看器。文档工厂将既不检查也不保证这些id的惟一性。

还是方法是一个抽象的三个其他方法一起使用来管理资源的上传:

还是包装在一起的功能这三个方法,并返回一个URL时上传资源承诺解决了。这个URL可以用来加载文档LoadFromUri

上传的数据块,每个块的大小是由上传uploadBlobChunkSize

承诺该方法可以获得进步的事件。指DocumentUploadProgress为更多的信息。

承诺对象通过调用立即返回还是的类型是AbortableJQueryPromise,通常的jQuery承诺对象的扩展。这类添加一个额外的方法,中止相同的功能AbortUploadDocument而不是静态的,因此不需要上传文件的URI。如果上传失败,失败回调到承诺对象将被设置为与所有三个参数。看到承诺为更多的信息。

该方法使用JavaScript文件对象获得访问一个文件在本地机器上。

注意,浏览器必须支持FileReader API为了操作文件系统数据在本地机器上。如果FileReader API不支持,就会抛出一个错误IsBrowserError将返回真正的

使用文档库上传如何使用此方法的详细信息和所使用的各种选项。

例子< / div >

这个例子将上传文件从本地机器,然后下载LEADTOOLS文档对象可以使用。

UploadFile.ts< / div >
DocumentHelper.ts< / div >
UploadFile.js< / div >
DocumentHelper.js< / div >
UploadFile.html< / div >< / div >< div id ="GenericContainerEntry6366" class="GenericContainerEntry">
进口{DocumentHelper}从“. . / . . /工具/ DocumentHelper”;出口DocumentFactory_UploadFileExample {公共构造函数(){lt.RasterSupport.setLicenseUri (“https://demo.leadtools.com/licenses/v200/LEADTOOLSEVAL.txt”,“EVAL”,);DocumentHelper.initFactory ();}公共运行= (buttonID:字符串)= > {常量exampleButton = . getelementbyid (buttonID);/ /添加一个文件选择常量fileInput = document.createElement (“输入”);fileInput。类型=“文件”;exampleButton.parentNode.appendChild (fileInput);/ /添加一个“上传”按钮常量uploadButton = document.createElement (“按钮”);uploadButton。类型=“按钮”;uploadButton。innerHTML =“点击上传”;exampleButton.parentNode.appendChild (uploadButton);uploadButton。onclick = () = > {常量文件= fileInput.files [0];如果(文件){alert (“没有文件!”);返回;}/ /上传它DocumentHelper.log (“上传……”);lt.Document.DocumentFactory.uploadFile(文件).done ((uri) = > {/ /完成,现在加载它DocumentHelper.log (“完成上传。现在加载……”);常量loadDocumentOptions =lt.Document.LoadDocumentOptions ();/ /设置名称loadDocumentOptions.name = file.name;lt.Document.DocumentFactory。loadDocumentOptions loadFromUri (uri).done ((doc) = > {DocumentHelper.log (“已经成功加载文档”);DocumentHelper.log (“叫”+ doc.name);DocumentHelper.log (" MIMEType是“+ doc.mimeType);DocumentHelper.log (“的页面数量+ doc.pages.count);})fail (DocumentHelper.showServiceError);})fail (DocumentHelper.showServiceError);}}}
出口DocumentHelper {静态showServiceError = (jqXHR statusText errorThrown) = > {alert (“从服务返回错误。有关详细信息,请参阅控制台”。);常量serviceError = lt.Document.ServiceError。parseError (jqXHR statusText errorThrown);console.error (serviceError);}静态日志=(信息:字符串、数据吗?任何)= > {常量outputElement = . getelementbyid (“输出”);如果(outputElement) {常量时间= (日期()).toLocaleTimeString ();常量textElement = document.createElement (“p”);textElement。innerHTML =(outputElement。childElementCount + 1) +“(”+时间+“:”+消息;outputElement。方法(textElement outputElement.firstChild);}如果数据(!)console.log(消息);其他的控制台。日志(消息、数据);}静态initFactory = () = > {/ /与DocumentsService通信,它必须运行!/ /更改这些参数匹配服务的路径。lt.Document.DocumentFactory。serviceHost =“http://localhost: 40000”;lt.Document.DocumentFactory。servicePath =”“;lt.Document.DocumentFactory。serviceApiPath =“api”;}}
进口{DocumentHelper}从“. . / . . /工具/ DocumentHelper”;出口DocumentFactory_UploadFileExample {构造函数(){lt.RasterSupport.setLicenseUri (“https://demo.leadtools.com/licenses/v200/LEADTOOLSEVAL.txt”,“EVAL”,);DocumentHelper.initFactory ();}运行= (buttonID) = > {常量exampleButton = . getelementbyid (buttonID);/ /添加一个文件选择常量fileInput = document.createElement (“输入”);fileInput。类型=“文件”;exampleButton.parentNode.appendChild (fileInput);/ /添加一个“上传”按钮常量uploadButton = document.createElement (“按钮”);uploadButton。类型=“按钮”;uploadButton。innerHTML =“点击上传”;exampleButton.parentNode.appendChild (uploadButton);uploadButton。onclick = () = > {常量文件= fileInput.files [0];如果(文件){alert (“没有文件!”);返回;}/ /上传它DocumentHelper.log (“上传……”);lt.Document.DocumentFactory.uploadFile(文件).done ((uri) = > {/ /完成,现在加载它DocumentHelper.log (“完成上传。现在加载……”);常量loadDocumentOptions =lt.Document.LoadDocumentOptions ();/ /设置名称loadDocumentOptions.name = file.name;lt.Document.DocumentFactory。loadDocumentOptions loadFromUri (uri).done ((doc) = > {DocumentHelper.log (“已经成功加载文档”);DocumentHelper.log (“叫”+ doc.name);DocumentHelper.log (" MIMEType是“+ doc.mimeType);DocumentHelper.log (“的页面数量+ doc.pages.count);})fail (DocumentHelper.showServiceError);})fail (DocumentHelper.showServiceError);}}}
出口DocumentHelper {静态showServiceError = (jqXHR statusText errorThrown) = > {alert (“从服务返回错误。有关详细信息,请参阅控制台”。);常量serviceError = lt.Document.ServiceError。parseError (jqXHR statusText errorThrown);console.error (serviceError);}静态日志=(消息、数据)= > {常量outputElement = . getelementbyid (“输出”);如果(outputElement) {常量时间= (日期()).toLocaleTimeString ();常量textElement = document.createElement (“p”);textElement。innerHTML =(outputElement。childElementCount + 1) +“(”+时间+“:”+消息;outputElement。方法(textElement outputElement.firstChild);}如果数据(!)console.log(消息);其他的控制台。日志(消息、数据);}静态initFactory = () = > {/ /与DocumentsService通信,它必须运行!/ /更改这些参数匹配服务的路径。lt.Document.DocumentFactory。serviceHost =“http://localhost: 40000”;lt.Document.DocumentFactory。servicePath =”“;lt.Document.DocumentFactory。serviceApiPath =“api”;}}
< !doctype html >< html lang =“en”><标题>文档例子|还是< /名称><头>< script src =“https://code.jquery.com/jquery-2.2.4.min.js”诚信=“sha256-BbhdlvQf / xTY9gja0Dq3HiwQF8LaCRTXxZKRutelT44 = "crossorigin =“匿名”> < /脚本>< script src =“. . / . . / LT / Leadtools.js”> < /脚本>< script src =“. . / . . / LT / Leadtools.Controls.js”> < /脚本>< script src =“. . / . . / LT / Leadtools.Annotations.Engine.js”> < /脚本>< script src =“. . / . . / LT / Leadtools.Annotations.Designers.js”> < /脚本>< script src =“. . / . . / LT / Leadtools.Annotations.Rendering.Javascript.js”> < /脚本>< script src =“. . / . . / LT / Leadtools.Annotations.Automation.js”> < /脚本>< script src =“. . / . . / LT / Leadtools.ImageProcessing.Main.js”> < /脚本>< script src =“. . / . . / LT / Leadtools.ImageProcessing.Color.js”> < /脚本>< script src =“. . / . . / LT / Leadtools.ImageProcessing.Core.js”> < /脚本>< script src =“. . / . . / LT / Leadtools.ImageProcessing.Effects.js”> < /脚本>< script src =“. . / . . / LT / Leadtools.Document.js”> < /脚本>< script src =“. . / . . / LT / Leadtools.Document.Viewer.js”> < /脚本>< link rel =“样式表”类型=“文本/ css”href =“. . / . . / css / examples.css”>< !——所有演示文件捆绑和附加到窗口- - >< script src =“. . / . . / bundle.js”类型=“text / javascript”> < /脚本>< / >头<身体>< div ><按钮类型=“按钮”id =“exampleButton”> > < /按钮运行例子< / div >< div id =“输出”> < / div >< div >< img id =“img”/ >< / div >< /身体><脚本>窗口。onload = () = > {常量示例=window.examples.DocumentFactory.UploadFile ();example.run (“exampleButton”);};> < /脚本< / html >
需求< / div >目标平台
帮助21.0.2021.7.2版本< / div >< !--BEGIN Copyright notice--> 188金宝搏的网址客服|支持|联系我们|知识产权的通知
©1991 - 2021领先的技术公司。保留所有权利。< !--END Copyright notice-->
Leadtools。文档一个ssembly< / div >