我无法使用以下javascript代码将附件上传到Corda节点。我收到“HTTP ERROR 400问题访问/上传/附件。原因:收到没有文件的上传请求”。
uploadmodalInstance.attachmentfile = document.getElementById('attachmentfile').files[0];
var formdata = new FormData();
formdata.append('jar', uploadmodalInstance.attachmentfile);
$http.defaults.headers.common['Accept'] = 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8';
// NOW UPLOAD THE FILES.
$http({
method: 'POST',
url: '/upload/attachment',
data: formdata,
headers: {'Content-Type': 'multipart/form-data; boundary=----WebKitFormBoundaryqtDm9u9ZQbwnwy3A'}
}).then(
(result) => {
uploadmodalInstance.displayMessage(result); //success
},
(result) => {
uploadmodalInstance.displayMessage(result); //failure
}
);
但是,我可以使用HTML上传相同的附件,如下所示:
<form action="http://localhost:10007/upload/attachment" method="post" enctype="multipart/form-data">
<div class="form-group">
<input type="file" name="jar" class="form-control">
</div>
<br>
<button type="submit" class="btn btn-default">Upload blacklist</button>
</form>
javascript有什么问题?我在Firefox开发人员工具中检查了header和formdata,在两种情况下都是相同的。
这是包含attachmentfile元素的HTML页面代码:
<script type="text/ng-template" id="demoAppUploadModal.html">
<div class="modal-header">
<h4 class="modal-title">Upload a Document</h4>
</div>
<form>
<div class="modal-body">
<div class="form-group">
<label for="attachmentfile" class="control-label">Document Attachment:</label>
<input type="file" ng-model="uploadmodalInstance.form.attachmentfile" class="form-control" id="attachmentfile">
</div>
<div ng-show="modalInstance.formError" class="form-group">
<div class="alert alert-danger" role="alert">
<span class="glyphicon glyphicon-exclamation-sign" aria-hidden="true"></span>
<span class="sr-only">Error:</span>
Enter valid parameters
</div>
</div>
</div>
<div class="modal-footer">
<button ng-click="uploadmodalInstance.cancel()" type="button" class="btn btn-default">Cancel</button>
<button ng-click="uploadmodalInstance.create()" type="button" class="btn btn-primary">Upload</button>
</div>
</form>
<!--form action="/upload/attachment" method="post" enctype="multipart/form-data">
<div class="form-group">
<input type="file" name="jar" class="form-control">
</div>
<br>
<button type="submit" class="btn btn-default">Upload Document</button>
</form -->
</script>
答案 0 :(得分:0)
因此,请记住在新版本的Corda中附件的工作方式有所不同。
我将在此处引用有关如何使用Corda附件的答案的文档。
要添加附件,必须首先将文件上传到节点,该节点返回可以使用TransactionBuilder.addAttachment()添加的唯一ID。附件可以通过RPC和Corda Node Shell进行上传和下载。
https://docs.corda.net/docs/corda-os/4.4/tutorial-attachments.html