我正在使用一个浏览器插件,它接收来自扫描仪的输入并返回一个 base64 编码的字符串。我正在尝试获取此字符串并将其用作表单帖子的内容。我不知所措。
var formElem = document.getElementById("fileUploadForm");
var imagedata;
Plugin.SelectedImagesCount = 1;
Plugin.SetSelectedImageIndex(0,0); // Set the 1st image as the first selected image.
Plugin.GetSelectedImagesSize(1); //jpeg
imagedata = Plugin.SaveSelectedImagesToBase64Binary();
//This is where I'd like to send the imagedata to the server
我试过搜索,但到目前为止我发现的唯一方法是构建自定义 http 来模拟表单提交。我想重用现有的文件上传表单。
<form id="fileUploadForm" method="POST" enctype="multipart/form-data">
<!-- Scanning -->
<select name="docType">
<option>1</option>
<option>2</option>
<option>3</option>
</select>
<button onClick="ScanImage(); return false;">Scan</button>
<!-- Uploading -->
<input id="DocUploadInput" type="file" name="RemoteFile" />
<button onClick="fileUpload(this.form,'/UploadDocument/'); return false;">Upload</button>
</form>