[英]Upload File Angular 2
如果您等待RC2,您將能夠使用除文本之外的其他有效負載。
例如Blob
的:
var headers = new Headers({'Content-Type': 'text/css'});
var body = new Blob(['body { color: red; }']);
return this.http.post('/url', body, { headers });
Arraybuffer
:
var headers = new Headers({'Content-Type': 'text/css'});
var body = new ArrayBuffer(512);
var longInt8View = new Uint8Array(body);
for (var i = 0; i < longInt8View.length; i++) {
longInt8View[i] = i % 255;
}
return this.http.post('/url', body, { headers });
FormData
的:
var body = new FormData();
body.append('test1', 'val1');
body.append('test2', 123456);
var blob = new Blob(['body { color: red; }'], {type: 'text/css'});
body.append("userfile", blob);
return this.http.post('/url', body, { headers });
處理HTTP請求的二進制內容要容易得多。 現在,由於Angular2僅接受文本有效負載作為輸入,因此很難(並且很難)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.