[英]How can I send a file to mail in html form using http request in nodejs server code?
[英]How can I make a http file upload server with nodejs? not using form
我想用nodejs創建一個http文件上傳服務器,而不是使用表單。 我看過很多帶form
fileupload示例。 但我需要一個服務器代碼,可以在api格式調用時接收文件。
例如,
服務器端是nodejs
(我很好奇)
客戶端是javascript
(XmlHttpRequest), C#
, python
,....等等。
當客戶端為文件上載調用api時,要在服務器端接收文件,我該怎么辦?
使用FormData。
var formData = new FormData();
formData.append("username", "Groucho");
formData.append("accountnum", 123456); // number 123456 is immediately converted to a string "123456"
// HTML file input, chosen by user
formData.append("userfile", fileInputElement.files[0]);
// JavaScript file-like object
var content = '<a id="a"><b id="b">hey!</b></a>'; // the body of the new file...
var blob = new Blob([content], { type: "text/xml"});
formData.append("webmasterfile", blob);
var request = new XMLHttpRequest();
request.open("POST", "http://foo.com/submitform.php");
request.send(formData);
從這里查看更多信息: https : //developer.mozilla.org/en-US/docs/Web/API/FormData/Using_FormData_Objects
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.