简体   繁体   English

自动上传 Priority-Web-SDK 文件

[英]Automating Priority-Web-SDK file upload

I would like to create a command line (or other automated) method for uploading files to priority using the Web-SDK.我想创建一个命令行(或其他自动化)方法来使用 Web-SDK 将文件上传到优先级。 The best solution I have right now seems to be a simple webform activated by a python script.我现在最好的解决方案似乎是一个由 py​​thon 脚本激活的简单网络表单。

Are there tools/examples for using Javascript and a file picker without opening the browser?是否有无需打开浏览器即可使用 Javascript 和文件选择器的工具/示例? Are there Priority-Web-SDK ports to other environments?是否有到其他环境的 Priority-Web-SDK 端口? C#, Python, etc? C#、Python 等?

Any other suggestions also welcome.任何其他建议也欢迎。

UPDATE June 14, 2020: 2020 年 6 月 14 日更新:
I was able to complete the task for this client using a combination of Javascript, Python and C#.我能够使用 Javascript、Python 和 C# 的组合完成此客户端的任务。 A tangled mess indeed, but files were uploaded.确实是一团糟,但文件已上传。 I am now revisiting the task and looking for cleaner solutions.我现在正在重新审视这项任务并寻找更清洁的解决方案。

I found a working and usable Node module to compact the program into an executable to make it a viable option for deployment.我找到了一个有效且可用的 Node 模块,可以将程序压缩为可执行文件,使其成为可行的部署选项。

So the question becomes more focused => creating the input for uploadDataUrl() or uploadFile() without a browser form.所以问题变得更加集中 => 在没有浏览器表单的情况下为 uploadDataUrl() 或 uploadFile() 创建输入。

You run node locally and use priority SDK.您在本地运行节点并使用优先级 SDK。

*As long as you work in an environment that is capable to render JS. *只要你在能够渲染 JS 的环境中工作。 You can send files through the function uploadFile .您可以通过函数uploadFile发送文件。 The data inside the file object need to be written as 64 base file .文件对象内的数据需要写为 64 base file

This nodejs script will upload a file to Priority.此 nodejs 脚本会将文件上传到 Priority。 Make sure that fetch-base64 is npm installed:确保fetch-base64已安装 npm:

"use strict";

const priority = require('priority-web-sdk');
const fetch = require('fetch-base64');

const configuration = {...};

async function uploadFile(formName, zoomVal, filepath, filename) {
  try {
    await priority.login(configuration);
    let form = await priority.formStartEx(formName, null, null, null, 1, {zoomValue: zoomVal});
    await form.startSubForm("EXTFILES", null ,null);
    let data = await fetch.local(filepath + '/' + filename);
    let f = await form.uploadDataUrl(data[0], filename.match(/\..+$/i)[0], () => {});
    await form.fieldUpdate("EXTFILENAME", f.file); // Path
    await form.fieldUpdate("EXTFILEDES", filename);  // Name
    await form.saveRow(0);
  } catch(err) {
      console.log('Something bad happened:');
      console.dir(err);
  }
}

uploadFile('AINVOICES', 'T9679', 'C:/my/path', 'a.pdf');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM