Skip to Content
網頁應用程式設計--使用 Node 和 Express
book

網頁應用程式設計--使用 Node 和 Express

by Ethan Brown
December 2014
Intermediate to advanced
336 pages
6h 34m
Chinese
GoTop Information, Inc.
Content preview from 網頁應用程式設計--使用 Node 和 Express
表單處理
|
95
});
});
app.post('/contest/vacation-photo/:year/:month', function(req, res){
var form = new formidable.IncomingForm();
form.parse(req, function(err, fields, files){
if(err) return res.redirect(303, '/error');
console.log('received fields:');
console.log(fields);
console.log('received files:');
console.log(files);
res.redirect(303, '/thank-you');
});
});
(年份與月份會被指定為
路由參數
,第十四章將會學習這個部分)。繼續執行它,並查
看主控台的記錄。你會看到,你的表單欄位如你預期的過來了:它是一個物件,裡面有
對應至你的欄位名稱的特性。
files
物件含有更多資料,但它比較簡單。對於每一個被
上傳的檔案,你會看到裡面有大小的特性、上傳的路徑(通常是一個在暫時性目錄中的
隨機名稱),及使用者上傳的原始檔案名稱(基於安全與隱私的考量,只有檔案名稱,
沒有全部的路徑)。
現在你可以任意地處理這個檔案,你可以將它存在資料庫、複製到更持久的地方,或上
傳到雲端式檔案儲存系統。記得,如果你依賴在地存儲來儲存檔案,你的應用程式的大
小就不會很理想,因此就不適合雲端式託管。我們會在第十三章回來討論這個範例。 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

HTML5與JAVASCRIPT WEB APPS開發實務

HTML5與JAVASCRIPT WEB APPS開發實務

Wesley Hales
jQuery Mobile建置與執行

jQuery Mobile建置與執行

Maximiliano Firtman

Publisher Resources

ISBN: 9789863474371