Skip to Content
Node与Express开发(第2版)
book

Node与Express开发(第2版)

by Ethan Brown
June 2021
Intermediate to advanced
290 pages
9h 21m
Chinese
Posts & Telecom Press
Content preview from Node与Express开发(第2版)
128
|
第
13
章
到本章后面再完成它。
一般来说,你永远都不应该信任用户上传的东西,因为它可能会成为攻击你
的网站的媒介。例如,恶意用户可以轻易地获取有害的可执行文件,将其
以
.jpg
后缀重命名
,并上传上去,作为攻击的第一步(企图以后能找到机会
再执行它)。与此类似,这里直接使用浏览器提供的
name
属性来命名文件也
是要冒一点儿风险的,因为可能会有人利用这一点,在文件名里面插入一些
特殊字符。要让代码完全安全,应该给文件随机的文件名,并且只接受一个
扩展名(确保只包含字母和数字)。
即使文件系统持久化有其不足之处,但是它频繁被用于中间文件的存储,因此知道如何使
用
Node
的文件系统库是很有用的
。不过,为了弥补文件系统持久化的缺陷,让我们来看
看云持久化。
13.2
 云持久化
云持久化越来越流行,其提供的服务既便宜又稳定,强烈建议你将它们利用起来。
要使用这些云服务,需要做一些预备工作。创建账号自不用说,你还要理解应用跟云服务
是如何认证身份的,另外理解一些基本术语也是很有用的(例如,
AW
S
把文件存储的单元
叫作
bucket
,而
Azure
将它们叫作
container
)。详细阐述这些信息超出了本书的范畴,何
况官方也有很好的参考文档。
• AWS
:
Getting Started in Node.js
• Azure for JavaScript and Node.js Developers
好消息是,一旦你完成初始的设置,使用云持久化就很简单了。下面是把文件保存到亚马
逊的
S3
的例子,看看有多么简单:
const filename ...
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

面向对象的思考过程(原书第5版)

面向对象的思考过程(原书第5版)

马特 魏斯费尔德
精通模块化JavaScript

精通模块化JavaScript

Nicolás Bevacqua

Publisher Resources

ISBN: 9787115565099