{"id":308399,"date":"2020-08-13T03:00:09","date_gmt":"2020-08-13T03:00:09","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=308399"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=308399","title":{"rendered":"NestJS. \u0417\u0430\u0433\u0440\u0443\u0437\u043a\u0430 \u0444\u0430\u0439\u043b\u043e\u0432 \u0432 S3 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435 (minio)"},"content":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/post\/514948\/\">NestJS \u2014 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u044b\u0445, \u043c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u0443\u0435\u043c\u044b\u0445 \u0441\u0435\u0440\u0432\u0435\u0440\u043d\u044b\u0445 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0439 \u043d\u0430 \u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u0435 Node.js. \u0412\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0432\u0441\u0442\u0440\u0435\u0442\u0438\u0442\u044c \u0443\u0442\u0432\u0435\u0440\u0436\u0434\u0435\u043d\u0438\u0435, \u0447\u0442\u043e NestJS \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u043e-\u043d\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u044b\u043c \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u043e\u043c. \u0418\u043c\u0435\u0435\u0442\u0441\u044f \u0432 \u0432\u0438\u0434\u0443, \u0447\u0442\u043e \u043e\u043d \u043c\u043e\u0436\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u043d\u0430 \u0431\u0430\u0437\u0435 \u043e\u0434\u043d\u043e\u0433\u043e \u0438\u0437 \u0434\u0432\u0443\u0445 \u0444\u0440\u0435\u0439\u043c\u043e\u0440\u043a\u043e\u0432 \u043f\u043e \u0412\u0430\u0448\u0435\u043c\u0443 \u0432\u044b\u0431\u043e\u0440\u0443: NestJS+Express \u0438\u043b\u0438 NestJS+Fastify. \u042d\u0442\u043e \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0442\u0430\u043a, \u0438\u043b\u0438 \u043f\u043e\u0447\u0442\u0438 \u0442\u0430\u043a. \u042d\u0442\u0430 \u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u043e-\u043d\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u044c \u0437\u0430\u043a\u0430\u043d\u0447\u0438\u0432\u0430\u0435\u0442\u0441\u044f, \u043d\u0430 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 Content-Type: multipart\/form-data. \u0422\u043e \u0435\u0441\u0442\u044c \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043d\u0430 \u0432\u0442\u043e\u0440\u043e\u0439 \u0434\u0435\u043d\u044c \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438. \u0418 \u044d\u0442\u043e \u043d\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u043e\u0439, \u0435\u0441\u043b\u0438 \u0412\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0435 \u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u0443 NestJS+Express \u2014 \u0432 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 \u0435\u0441\u0442\u044c \u043f\u0440\u0438\u043c\u0435\u0440 \u0440\u0430\u0431\u043e\u0442\u044b \u0434\u043b\u044f Content-Type: multipart\/form-data. \u0414\u043b\u044f NestJS+Fastify \u0442\u0430\u043a\u043e\u0433\u043e \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u043d\u0435\u0442, \u0438 \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432 \u0432 \u0441\u0435\u0442\u0438 \u043d\u0435 \u0442\u0430\u043a \u0443\u0436 \u0438 \u043c\u043d\u043e\u0433\u043e. \u0418 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0438\u0437 \u044d\u0442\u0438\u0445 \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432 \u0438\u0434\u0443\u0442 \u043f\u043e \u0432\u0435\u0441\u044c\u043c\u0430 \u0443\u0441\u043b\u043e\u0436\u043d\u0435\u043d\u043d\u043e\u043c\u0443 \u043f\u0443\u0442\u0438.<\/p>\n<p>  \u0412\u044b\u0431\u0438\u0440\u0430\u044f \u043c\u0435\u0436\u0434\u0443 \u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u043e\u0439 NestJS+Fastify \u0438 NestJS+Express \u044f \u0441\u0434\u0435\u043b\u0430\u043b \u0432\u044b\u0431\u043e\u0440 \u0432 \u0441\u0442\u043e\u0440\u043e\u043d\u0443 NestJS+Fastify. \u0417\u043d\u0430\u044f \u0441\u043a\u043b\u043e\u043d\u043d\u043e\u0441\u0442\u044c \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u0432 \u0432 \u043b\u044e\u0431\u043e\u0439 \u043d\u0435\u043f\u043e\u043d\u044f\u0442\u043d\u043e\u0439 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u0438 \u0432\u0435\u0448\u0430\u0442\u044c \u043d\u0430 \u043e\u0431\u044a\u0435\u043a\u0442 req \u0432 Express \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 \u0438 \u0442\u0430\u043a \u043e\u0431\u0449\u0430\u0442\u044c\u0441\u044f \u043c\u0435\u0436\u0434\u0443 \u0440\u0430\u0437\u043d\u044b\u043c\u0438 \u0447\u0430\u0441\u0442\u044f\u043c\u0438 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u044f \u0442\u0432\u0435\u0440\u0434\u043e \u0440\u0435\u0448\u0438\u043b \u0447\u0442\u043e Express \u0432 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c \u043f\u0440\u043e\u0435\u043a\u0442\u0435 \u043d\u0435 \u0431\u0443\u0434\u0435\u0442.<br \/>  <a name=\"habracut\"><\/a><br \/>  \u0422\u043e\u043b\u044c\u043a\u043e \u043d\u0443\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0440\u0435\u0448\u0438\u0442\u044c \u0442\u0435\u0445\u043d\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0432\u043e\u043f\u0440\u043e\u0441 \u0441 Content-Type: multipart\/form-data. \u0422\u0430\u043a\u0436\u0435 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0435 \u0447\u0435\u0440\u0435\u0437 \u0437\u0430\u043f\u0440\u043e\u0441\u044b Content-Type: multipart\/form-data \u0444\u0430\u0439\u043b\u044b \u044f \u043f\u043b\u0430\u043d\u0438\u0440\u043e\u0432\u0430\u043b \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0442\u044c \u0432 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435 S3. \u0412 \u044d\u0442\u043e\u043c \u043f\u043b\u0430\u043d\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 Content-Type: multipart\/form-data \u043d\u0430 \u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u0435 NestJS+Express \u043c\u0435\u043d\u044f \u0441\u043c\u0443\u0449\u0430\u043b\u0430 \u0442\u0435\u043c, \u0447\u0442\u043e \u043d\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u043b\u0430 \u0441 \u043f\u043e\u0442\u043e\u043a\u0430\u043c\u0438.<\/p>\n<h2>\u0417\u0430\u043f\u0443\u0441\u043a \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0430 S3<\/h2>\n<p>  S3 \u2014 \u044d\u0442\u043e \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 (\u043c\u043e\u0436\u043d\u043e \u0441\u043a\u0430\u0437\u0430\u0442\u044c, \u0445\u043e\u0442\u044f \u043d\u0435 \u0441\u043e\u0432\u0441\u0435\u043c \u0441\u0442\u0440\u043e\u0433\u043e, \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435 \u0444\u0430\u0439\u043b\u043e\u0432), \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u043e\u0435 \u043f\u043e \u043f\u0440\u043e\u0442\u043e\u043a\u043e\u043b\u0443 http. \u0418\u0437\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e S3 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u043b\u0441\u044f AWS. \u0412 \u043d\u0430\u0441\u0442\u043e\u044f\u0449\u0435\u0435 \u0432\u0440\u0435\u043c\u044f API S3 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u0438 \u0434\u0440\u0443\u0433\u0438\u043c\u0438 \u043e\u0431\u043b\u0430\u0447\u043d\u044b\u043c\u0438 \u0441\u0435\u0440\u0432\u0438\u0441\u0430\u043c\u0438. \u041d\u043e \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e. \u041f\u043e\u044f\u0432\u0438\u043b\u0438\u0441\u044c \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0441\u0435\u0440\u0432\u0435\u0440\u043e\u0432 S3, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0412\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u043e\u0434\u043d\u044f\u0442\u044c \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u043e, \u0447\u0442\u043e\u0431\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0438\u0445 \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438, \u0438, \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u043f\u043e\u0434\u043d\u044f\u0442\u044c \u0441\u0432\u043e\u0438 \u0441\u0435\u0440\u0432\u0435\u0440\u044b S3 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u043d\u0430 \u043f\u0440\u043e\u0434\u0435.<\/p>\n<p>  \u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u043d\u0443\u0436\u043d\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c\u0441\u044f \u0441 \u043c\u043e\u0442\u0438\u0432\u0430\u0446\u0438\u0435\u0439 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f S3 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0430 \u0434\u0430\u043d\u043d\u044b\u0445. \u0412 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0441\u043b\u0443\u0447\u0430\u044f\u0445 \u044d\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0441\u043d\u0438\u0437\u0438\u0442\u044c \u0437\u0430\u0442\u0440\u0430\u0442\u044b. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0434\u043b\u044f \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0440\u0435\u0437\u0435\u0440\u0432\u043d\u044b\u0445 \u043a\u043e\u043f\u0438\u0439 \u043c\u043e\u0436\u043d\u043e \u0432\u0437\u044f\u0442\u044c \u0441\u0430\u043c\u044b\u0435 \u043c\u0435\u0434\u043b\u0435\u043d\u043d\u044b\u0435 \u0438 \u0434\u0435\u0448\u0435\u0432\u044b\u0435 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0430 S3. \u0411\u044b\u0441\u0442\u0440\u044b\u0435 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0430 \u0441 \u0432\u044b\u0441\u043e\u043a\u0438\u043c \u0442\u0440\u0430\u0444\u0438\u043a\u043e\u043c (\u0442\u0440\u0430\u0444\u0438\u043a \u0442\u0430\u0440\u0438\u0444\u0438\u0446\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e) \u043d\u0430 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0443 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u0437 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0430, \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u0431\u0443\u0434\u0443\u0442 \u0441\u0442\u043e\u0438\u0442\u044c \u0441\u0440\u0430\u0432\u043d\u0438\u043c\u043e \u0441 SSD \u0434\u0438\u0441\u043a\u0430\u043c\u0438 \u0442\u043e\u0433\u043e \u0436\u0435 \u043e\u0431\u044a\u0435\u043c\u0430.<\/p>\n<p>  \u0411\u043e\u043b\u0435\u0435 \u0432\u0435\u0441\u043e\u043c\u044b\u043c \u043c\u043e\u0442\u0438\u0432\u043e\u043c \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f 1) \u0440\u0430\u0441\u0448\u0438\u0440\u044f\u0435\u043c\u043e\u0441\u0442\u044c \u2014 \u0412\u0430\u043c \u043d\u0435 \u043d\u0443\u0436\u043d\u043e \u0434\u0443\u043c\u0430\u0442\u044c \u043e \u0442\u043e\u043c, \u0447\u0442\u043e \u043c\u0435\u0441\u0442\u043e \u043d\u0430 \u0434\u0438\u0441\u043a\u0435 \u043c\u043e\u0436\u0435\u0442 \u0437\u0430\u043a\u043e\u043d\u0447\u0438\u0442\u044c\u0441\u044f, \u0438 2) \u043d\u0430\u0434\u0435\u0436\u043d\u043e\u0441\u0442\u044c \u2014 \u0441\u0435\u0440\u0432\u0435\u0440\u0430 \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0442 \u0432 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0435 \u0438 \u0412\u0430\u043c \u043d\u0435 \u043d\u0443\u0436\u043d\u043e \u0434\u0443\u043c\u0430\u0442\u044c \u043e \u0440\u0435\u0437\u0435\u0440\u0432\u043d\u043e\u043c \u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0438, \u0442\u0430\u043a \u043a\u0430\u043a \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043a\u043e\u043f\u0438\u0439 \u0435\u0441\u0442\u044c \u0432\u0441\u0435\u0433\u0434\u0430.<\/p>\n<p>  \u0414\u043b\u044f \u043f\u043e\u0434\u043d\u044f\u0442\u0438\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0441\u0435\u0440\u0432\u0435\u0440\u043e\u0432 S3 \u2014 minio \u2014 \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u043e \u043d\u0443\u0436\u0435\u043d \u0442\u043e\u043b\u044c\u043a\u043e \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u043d\u044b\u0439 \u043d\u0430 \u043a\u043e\u043c\u043f\u044c\u044e\u0442\u0435\u0440\u0435 docker \u0438 docker-compose. \u0421\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0432\u0443\u044e\u0449\u0438\u0439 \u0444\u0430\u0439\u043b docker-compose.yml:<\/p>\n<pre><code class=\"plaintext\">version: '3' services:   minio1:     image: minio\/minio:RELEASE.2020-08-08T04-50-06Z     volumes:       - .\/s3\/data1-1:\/data1       - .\/s3\/data1-2:\/data2     ports:       - '9001:9000'     environment:       MINIO_ACCESS_KEY: minio       MINIO_SECRET_KEY: minio123     command: server http:\/\/minio{1...4}\/data{1...2}     healthcheck:       test: ['CMD', 'curl', '-f', 'http:\/\/localhost:9000\/minio\/health\/live']       interval: 30s       timeout: 20s       retries: 3    minio2:     image: minio\/minio:RELEASE.2020-08-08T04-50-06Z     volumes:       - .\/s3\/data2-1:\/data1       - .\/s3\/data2-2:\/data2     ports:       - '9002:9000'     environment:       MINIO_ACCESS_KEY: minio       MINIO_SECRET_KEY: minio123     command: server http:\/\/minio{1...4}\/data{1...2}     healthcheck:       test: ['CMD', 'curl', '-f', 'http:\/\/localhost:9000\/minio\/health\/live']       interval: 30s       timeout: 20s       retries: 3    minio3:     image: minio\/minio:RELEASE.2020-08-08T04-50-06Z     volumes:       - .\/s3\/data3-1:\/data1       - .\/s3\/data3-2:\/data2     ports:       - '9003:9000'     environment:       MINIO_ACCESS_KEY: minio       MINIO_SECRET_KEY: minio123     command: server http:\/\/minio{1...4}\/data{1...2}     healthcheck:       test: ['CMD', 'curl', '-f', 'http:\/\/localhost:9000\/minio\/health\/live']       interval: 30s       timeout: 20s       retries: 3    minio4:     image: minio\/minio:RELEASE.2020-08-08T04-50-06Z     volumes:       - .\/s3\/data4-1:\/data1       - .\/s3\/data4-2:\/data2     ports:       - '9004:9000'     environment:       MINIO_ACCESS_KEY: minio       MINIO_SECRET_KEY: minio123     command: server http:\/\/minio{1...4}\/data{1...2}     healthcheck:       test: ['CMD', 'curl', '-f', 'http:\/\/localhost:9000\/minio\/health\/live']       interval: 30s       timeout: 20s       retries: 3 <\/code><\/pre>\n<p>  \u0417\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u2014 \u0438 \u0431\u0435\u0437 \u043f\u0440\u043e\u0431\u043b\u0435\u043c \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u043a\u043b\u0430\u0441\u0442\u0435\u0440 \u0438\u0437 4 \u0441\u0435\u0440\u0432\u0435\u0440\u043e\u0432 S3.<\/p>\n<h2>NestJS + Fastify + S3<\/h2>\n<p>  \u0420\u0430\u0431\u043e\u0442\u0443 \u0441 \u0441\u0435\u0440\u0432\u0435\u0440\u043e\u043c NestJS \u043e\u043f\u0438\u0448\u0443 \u0441 \u0441\u0430\u043c\u044b\u0445 \u043f\u0435\u0440\u0432\u044b\u0445 \u0448\u0430\u0433\u043e\u0432, \u0445\u043e\u0442\u044f \u0447\u0430\u0441\u0442\u044c \u044d\u0442\u043e\u0433\u043e \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b\u0430 \u043e\u0442\u043b\u0438\u0447\u043d\u043e \u043e\u043f\u0438\u0441\u0430\u043d\u0430 \u0432 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438. \u0423\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u0442\u0441\u044f CLI NestJS:<\/p>\n<pre><code class=\"actionscript\">npm install -g @nestjs\/cli<\/code><\/pre>\n<p>  \u0421\u043e\u0437\u0434\u0430\u0435\u0442\u0441\u044f \u043d\u043e\u0432\u044b\u0439 \u043f\u0440\u043e\u0435\u043a\u0442 NestJS:<\/p>\n<pre><code class=\"actionscript\">nest new s3-nestjs-tut<\/code><\/pre>\n<p>  \u0418\u043d\u0441\u0442\u0430\u043b\u043b\u0438\u0440\u0443\u044e\u0442\u0441\u044f \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u043f\u0430\u043a\u0435\u0442\u044b (\u0432\u043a\u043b\u044e\u0447\u0430\u044f \u0442\u0435 \u0447\u0442\u043e \u043d\u0443\u0436\u043d\u044b \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 S3):<\/p>\n<pre><code class=\"actionscript\"> npm install --save @nestjs\/platform-fastify fastify-multipart aws-sdk sharp npm install --save-dev @types\/fastify-multipart  @types\/aws-sdk @types\/sharp <\/code><\/pre>\n<p>  \u041f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u0432 \u043f\u0440\u043e\u0435\u043a\u0442\u0435 \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u0430 NestJS+Express. \u041a\u0430\u043a \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c Fastify \u043e\u043f\u0438\u0441\u0430\u043d\u043e \u0432 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 <a href=\"https:\/\/docs.nestjs.com\/techniques\/performance\" rel=\"nofollow\">docs.nestjs.com\/techniques\/performance<\/a>. \u0414\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u043f\u043b\u0430\u0433\u0438\u043d \u0434\u043b\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 Content-Type: multipart\/form-data \u2014 fastify-multipart<\/p>\n<pre><code class=\"javascript\">import { NestFactory } from '@nestjs\/core'; import {   FastifyAdapter,   NestFastifyApplication, } from '@nestjs\/platform-fastify'; import fastifyMultipart from 'fastify-multipart'; import { AppModule } from '.\/app.module';  async function bootstrap() {   const fastifyAdapter = new FastifyAdapter();   fastifyAdapter.register(fastifyMultipart, {     limits: {       fieldNameSize: 1024, \/\/ Max field name size in bytes       fieldSize: 128 * 1024 * 1024 * 1024, \/\/ Max field value size in bytes       fields: 10, \/\/ Max number of non-file fields       fileSize: 128 * 1024 * 1024 * 1024, \/\/ For multipart forms, the max file size       files: 2, \/\/ Max number of file fields       headerPairs: 2000, \/\/ Max number of header key=&gt;value pairs     },   });   const app = await NestFactory.create&lt;NestFastifyApplication&gt;(     AppModule,     fastifyAdapter,   );   await app.listen(3000, '127.0.0.1'); }  bootstrap(); <\/code><\/pre>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u043e\u043f\u0438\u0448\u0435\u043c \u0441\u0435\u0440\u0432\u0438\u0441, \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u044e\u0449\u0438\u0439 \u0444\u0430\u0439\u043b\u044b \u0432 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435 S3, \u0441\u043e\u043a\u0440\u0430\u0442\u0438\u0432 \u043a\u043e\u0434 \u043f\u043e \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0435 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0432\u0438\u0434\u043e\u0432 \u043e\u0448\u0438\u0431\u043e\u043a (\u043f\u043e\u043b\u043d\u044b\u0439 \u0442\u0435\u043a\u0441\u0442 \u0435\u0441\u0442\u044c \u0432 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u0430\u0440\u0438\u0438 \u0441\u0442\u0430\u0442\u044c\u0438):<\/p>\n<pre><code class=\"javascript\">import { Injectable, HttpException, BadRequestException } from '@nestjs\/common'; import { S3 } from 'aws-sdk'; import fastify = require('fastify'); import { AppResponseDto } from '.\/dto\/app.response.dto'; import * as sharp from 'sharp';  @Injectable() export class AppService {   async uploadFile(req: fastify.FastifyRequest): Promise&lt;any&gt; {      const promises = [];      return new Promise((resolve, reject) =&gt; {        const mp = req.multipart(handler, onEnd);        function onEnd(err) {         if (err) {           reject(new HttpException(err, 500));         } else {           Promise.all(promises).then(             data =&gt; {               resolve({ result: 'OK' });             },             err =&gt; {               reject(new HttpException(err, 500));             },           );         }       }        function handler(field, file, filename, encoding, mimetype: string) {         if (mimetype && mimetype.match(\/^image\\\/(.*)\/)) {           const imageType = mimetype.match(\/^image\\\/(.*)\/)[1];           const s3Stream = new S3({             accessKeyId: 'minio',             secretAccessKey: 'minio123',             endpoint: 'http:\/\/127.0.0.1:9001',             s3ForcePathStyle: true, \/\/ needed with minio?             signatureVersion: 'v4',           });           const promise = s3Stream             .upload(               {                 Bucket: 'test',                 Key: `200x200_${filename}`,                 Body: file.pipe(                   sharp()                     .resize(200, 200)                     [imageType](),                 ),               }             )             .promise();           promises.push(promise);         }         const s3Stream = new S3({           accessKeyId: 'minio',           secretAccessKey: 'minio123',           endpoint: 'http:\/\/127.0.0.1:9001',           s3ForcePathStyle: true, \/\/ needed with minio?           signatureVersion: 'v4',         });         const promise = s3Stream           .upload({ Bucket: 'test', Key: filename, Body: file })           .promise();         promises.push(promise);       }     });   } } <\/code><\/pre>\n<p>  \u0418\u0437 \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u0435\u0439 \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u043e\u0442\u043c\u0435\u0442\u0438\u0442\u044c, \u0447\u0442\u043e \u043c\u044b \u043f\u0438\u0448\u0435\u043c \u0432\u0445\u043e\u0434\u043d\u043e\u0439 \u043f\u043e\u0442\u043e\u043a \u0432 \u0434\u0432\u0430 \u0432\u044b\u0445\u043e\u0434\u043d\u044b\u0445 \u043f\u043e\u0442\u043e\u043a\u0430, \u0435\u0441\u043b\u0438 \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u0435\u0442\u0441\u044f \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0430. \u041e\u0434\u0438\u043d \u0438\u0437 \u043f\u043e\u0442\u043e\u043a\u043e\u0432 \u0441\u0436\u0438\u043c\u0430\u0435\u0442 \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0443 \u0434\u043e \u0440\u0430\u0437\u043c\u0435\u0440\u043e\u0432 200\u0445200. \u0412\u043e \u0432\u0441\u0435\u0445 \u0441\u043b\u0443\u0447\u0430\u044f\u0445 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0441\u0442\u0438\u043b\u044c \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u043f\u043e\u0442\u043e\u043a\u0430\u043c\u0438 (stream). \u041d\u043e \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u043e\u0442\u043b\u043e\u0432\u0438\u0442\u044c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0435 \u043e\u0448\u0438\u0431\u043a\u0438 \u0438 \u0432\u0435\u0440\u043d\u0443\u0442\u044c \u0438\u0445 \u0432 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440, \u043c\u044b \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c \u043c\u0435\u0442\u043e\u0434 promise(), \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d \u0432 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0435 aws-sdk. \u041f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0435 \u043f\u0440\u043e\u043c\u0438\u0441\u044b \u043d\u0430\u043a\u0430\u043f\u043b\u0438\u0432\u0430\u0435\u043c \u0432 \u043c\u0430\u0441\u0441\u0438\u0432\u0435 promises:<\/p>\n<pre><code class=\"javascript\">        const promise = s3Stream           .upload({ Bucket: 'test', Key: filename, Body: file })           .promise();         promises.push(promise); <\/code><\/pre>\n<p>  \u0418, \u0434\u0430\u043b\u0435\u0435, \u043e\u0436\u0438\u0434\u0430\u0435\u043c \u0438\u0445 \u0440\u0430\u0437\u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u0432 \u043c\u0435\u0442\u043e\u0434\u0435 <code>Promise.all(promises)<\/code>.<\/p>\n<p>  \u041a\u043e\u0434 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0442\u0430\u043a\u0438 \u043f\u0440\u0438\u0448\u043b\u043e\u0441\u044c \u043f\u0440\u043e\u0431\u0440\u043e\u0441\u0438\u0442\u044c FastifyRequest \u0432 \u0441\u0435\u0440\u0432\u0438\u0441:<\/p>\n<pre><code class=\"javascript\">import { Controller, Post, Req } from '@nestjs\/common'; import { AppService } from '.\/app.service'; import { FastifyRequest } from 'fastify';  @Controller() export class AppController {   constructor(private readonly appService: AppService) {}    @Post('\/upload')   async uploadFile(@Req() req: FastifyRequest): Promise&lt;any&gt; {     const result = await this.appService.uploadFile(req);     return result;   } } <\/code><\/pre>\n<p>  \u0417\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442\u0441\u044f \u043f\u0440\u043e\u0435\u043a\u0442:<\/p>\n<pre><code class=\"actionscript\">npm run start:dev<\/code><\/pre>\n<p>  \u0420\u0435\u043f\u043e\u0437\u0438\u0442\u0430\u0440\u0438\u0439 \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/github.com\/apapacy\/s3-nestjs-tut\" rel=\"nofollow\">github.com\/apapacy\/s3-nestjs-tut<\/a><\/p>\n<p>  apapacy@gmail.com<br \/>  13 \u0430\u0432\u0433\u0443\u0441\u0442\u0430 2020 \u0433\u043e\u0434\u0430<\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/514948\/\"> https:\/\/habr.com\/ru\/post\/514948\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/post\/514948\/\">NestJS \u2014 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u044b\u0445, \u043c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u0443\u0435\u043c\u044b\u0445 \u0441\u0435\u0440\u0432\u0435\u0440\u043d\u044b\u0445 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0439 \u043d\u0430 \u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u0435 Node.js. \u0412\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0432\u0441\u0442\u0440\u0435\u0442\u0438\u0442\u044c \u0443\u0442\u0432\u0435\u0440\u0436\u0434\u0435\u043d\u0438\u0435, \u0447\u0442\u043e NestJS \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u043e-\u043d\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u044b\u043c \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u043e\u043c. \u0418\u043c\u0435\u0435\u0442\u0441\u044f \u0432 \u0432\u0438\u0434\u0443, \u0447\u0442\u043e \u043e\u043d \u043c\u043e\u0436\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u043d\u0430 \u0431\u0430\u0437\u0435 \u043e\u0434\u043d\u043e\u0433\u043e \u0438\u0437 \u0434\u0432\u0443\u0445 \u0444\u0440\u0435\u0439\u043c\u043e\u0440\u043a\u043e\u0432 \u043f\u043e \u0412\u0430\u0448\u0435\u043c\u0443 \u0432\u044b\u0431\u043e\u0440\u0443: NestJS+Express \u0438\u043b\u0438 NestJS+Fastify. \u042d\u0442\u043e \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0442\u0430\u043a, \u0438\u043b\u0438 \u043f\u043e\u0447\u0442\u0438 \u0442\u0430\u043a. \u042d\u0442\u0430 \u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u043e-\u043d\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u044c \u0437\u0430\u043a\u0430\u043d\u0447\u0438\u0432\u0430\u0435\u0442\u0441\u044f, \u043d\u0430 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 Content-Type: multipart\/form-data. \u0422\u043e \u0435\u0441\u0442\u044c \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043d\u0430 \u0432\u0442\u043e\u0440\u043e\u0439 \u0434\u0435\u043d\u044c \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438. \u0418 \u044d\u0442\u043e \u043d\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u043e\u0439, \u0435\u0441\u043b\u0438 \u0412\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0435 \u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u0443 NestJS+Express \u2014 \u0432 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 \u0435\u0441\u0442\u044c \u043f\u0440\u0438\u043c\u0435\u0440 \u0440\u0430\u0431\u043e\u0442\u044b \u0434\u043b\u044f Content-Type: multipart\/form-data. \u0414\u043b\u044f NestJS+Fastify \u0442\u0430\u043a\u043e\u0433\u043e \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u043d\u0435\u0442, \u0438 \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432 \u0432 \u0441\u0435\u0442\u0438 \u043d\u0435 \u0442\u0430\u043a \u0443\u0436 \u0438 \u043c\u043d\u043e\u0433\u043e. \u0418 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0438\u0437 \u044d\u0442\u0438\u0445 \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432 \u0438\u0434\u0443\u0442 \u043f\u043e \u0432\u0435\u0441\u044c\u043c\u0430 \u0443\u0441\u043b\u043e\u0436\u043d\u0435\u043d\u043d\u043e\u043c\u0443 \u043f\u0443\u0442\u0438.<\/p>\n<p>  \u0412\u044b\u0431\u0438\u0440\u0430\u044f \u043c\u0435\u0436\u0434\u0443 \u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u043e\u0439 NestJS+Fastify \u0438 NestJS+Express \u044f \u0441\u0434\u0435\u043b\u0430\u043b \u0432\u044b\u0431\u043e\u0440 \u0432 \u0441\u0442\u043e\u0440\u043e\u043d\u0443 NestJS+Fastify. \u0417\u043d\u0430\u044f \u0441\u043a\u043b\u043e\u043d\u043d\u043e\u0441\u0442\u044c \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u0432 \u0432 \u043b\u044e\u0431\u043e\u0439 \u043d\u0435\u043f\u043e\u043d\u044f\u0442\u043d\u043e\u0439 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u0438 \u0432\u0435\u0448\u0430\u0442\u044c \u043d\u0430 \u043e\u0431\u044a\u0435\u043a\u0442 req \u0432 Express \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 \u0438 \u0442\u0430\u043a \u043e\u0431\u0449\u0430\u0442\u044c\u0441\u044f \u043c\u0435\u0436\u0434\u0443 \u0440\u0430\u0437\u043d\u044b\u043c\u0438 \u0447\u0430\u0441\u0442\u044f\u043c\u0438 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u044f \u0442\u0432\u0435\u0440\u0434\u043e \u0440\u0435\u0448\u0438\u043b \u0447\u0442\u043e Express \u0432 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c \u043f\u0440\u043e\u0435\u043a\u0442\u0435 \u043d\u0435 \u0431\u0443\u0434\u0435\u0442.  <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-308399","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/308399","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=308399"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/308399\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=308399"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=308399"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=308399"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}