1
我在Spring MVC中使用Angular 2。我目前有一個Upload組件,它對Spring後端進行AJAX調用,並從.csv文件返回解析數據的響應。Angular 2 Multipart AJAX Upload
export class UploadComponent {
uploadFile: function(){
var resp = this;
var data = $('input[type="file"]')[0].files[0];
this.fileupl = data;
var fd = new FormData();
fd.append("file", data);
$.ajax({
url: "uploadFile",
type: "POST",
data: fd,
processData: false,
contentType: false,
success: function(response) {
resp.response = response;
},
error: function(jqXHR, textStatus, errorMessage) {
console.log(errorMessage);
}
});
};
}
這個工程,我得到一個有效的迴應;然而,是否有更多的角度來傳遞這個文件到Spring並接收響應?我一直在尋找到創建可注射的服務,並使用訂閱,但我一直在努力得到響應
檢查此答案以獲取如何上傳文件的示例http://stackoverflow.com/questions/32423348/angular2-post-uploaded-file –