**文書の過去の版を表示しています。**
20210218
大容量ファイルの先頭を送信
index.pug
h1 #{title} p this is #{title} p Upload your fasta file below form(action="./upload" method="POST" enctype="multipart/form-data") input(type="file", name="file" id="inputfile") button(type="button" onclick="file_upload()" value="Upload") p(id="text") //script(src="./javascripts/main.js") script. var slice_size = 100 * 1024 * 1024; var files; var file; var slice_file; var reader = new FileReader(); var content; var fileData = {}; function file_upload() { var slice_file = $("#inputfile")[0].files[0].slice(0,slice_size); reader.readAsText(slice_file); reader.onload = function() { content = reader.result; } fileData.fileContent = content; $.ajax({ type: "POST", url: "./upload/", data: fileData, dataType: "json", }) .done(function(res){ console.log("success"); }) .fail(function(res){ console.log("falied"); }); }
大容量ファイルの転送を可能にするために、 app.js
を以下の部分を
app.use(bodyParser.json()); app.use(bodyParser.urlencoded({ extended: false }));
以下のように変更
app.use(bodyParser.json({ extended: true, limit: '1000mb' })); app.use(bodyParser.urlencoded({ extended: true, limit: '1000mb' }));
これにより、1GBまでのデータの転送をサーバが受け付けてくれるようになる。
以下のサイトを参照 https://swallow-incubate.com/archives/blog/20190402
転送速度テスト
1.伊藤PCでローカルで起動したサーバにChromeでjsonを送信
1MB送信 POST /upload/ 200 70.234 ms - 446 10MB送信 POST /upload/ 200 614.057 ms - 446 100MB送信 POST /upload/ 200 5604.368 ms - 446
2.m50v253n3サーバのテスト環境にデプロイした状態で、伊藤PCからm50v253n3サーバへ100MBのjsonを送信
Chrome:POST /upload/ 200 9407.304 ms - 446 Edge:POST /upload/ 200 9345.186 ms - 446 Firefox:POST /upload/ 200 10068.833 ms - 446