• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript mime-types.contentType函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了TypeScript中mime-types.contentType函数的典型用法代码示例。如果您正苦于以下问题:TypeScript contentType函数的具体用法?TypeScript contentType怎么用?TypeScript contentType使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了contentType函数的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。

示例1: deploy

 async deploy(args) {
   this._s3 = new (this._getAWS(this.resources)).S3();
   let bucket = this.resources.target;
   let source = path.resolve(this.resources.source);
   this.bucket = bucket;
   this.source = source;
   console.log("Deploy", source, "on S3 Bucket", bucket);
   await this.createBucket(bucket);
   let files = Finder.from(source).findFiles();
   // Should implement multithread here - cleaning too
   for (let i in files) {
     let file = files[i];
     let key = path.relative(source, file);
     // Need to have mimetype to serve the content correctly
     let mimetype = mime.contentType(path.extname(file));
     await this._s3
       .putObject({
         Bucket: bucket,
         Body: fs.createReadStream(file),
         Key: key,
         ContentType: mimetype
       })
       .promise();
     console.log("Uploaded", file, "to", key, "(" + mimetype + ")");
   }
   if (!this.resources.staticWebsite) {
     return;
   }
   await this._createWebsite();
 }
开发者ID:loopingz,项目名称:webda-shell,代码行数:30,代码来源:s3.ts


示例2: if

 files.forEach(file => {
   let info: any = {};
   if (typeof file === "string") {
     info.src = file;
     info.key = path.relative(process.cwd(), file);
   } else if (file.src === undefined || file.key === undefined) {
     throw Error("Should have src and key defined");
   } else {
     info.src = file.src;
     info.key = file.key;
   }
   // Need to have mimetype to serve the content correctly
   let mimetype = mime.contentType(path.extname(info.src));
   promise = promise
     .then(() => {
       return this._s3
         .putObject({
           Bucket: bucket,
           Body: fs.createReadStream(info.src),
           Key: info.key,
           ContentType: mimetype
         })
         .promise();
     })
     .then(() => {
       console.log(
         "Uploaded",
         info.src,
         "to",
         info.key,
         "(" + mimetype + ")"
       );
     });
 });
开发者ID:loopingz,项目名称:webda-shell,代码行数:34,代码来源:aws.ts


示例3: serverRequest

export function serverRequest(
	settings: Partial<ReactConverterSettings>,
	req: IncomingMessage,
	res: ServerResponse
) {
	const baseFolder = path.resolve(process.cwd(), process.env.DOCS || 'docs')

	let url = req.url

	if (!url) {
		return
	}

	url = decodeURIComponent(url)

	if (url.startsWith('/favicon.ico')) {
		url = favicon
	}

	if (url.startsWith(ASSETS)) {
		const filePath = path.join(__dirname, url.slice(ASSETS.length))
		res.setHeader('Content-Type', mime.contentType(path.extname(filePath)))
		return fs.readFileSync(filePath)
	}

	const urlPath = path.join(baseFolder, url)

	if (fs.existsSync(urlPath) && fs.statSync(urlPath).isFile()) {
		return fs.readFileSync(urlPath)
	} else {
		let indexPath = path.join(baseFolder, url, 'index.json')
		if (fs.existsSync(indexPath)) {
			const content = fs.readFileSync(indexPath).toString()
			res.setHeader('Content-Type', 'text/html; charset=utf-8')
			return renderHTML(JSON.parse(content).reflection, settings)
		} else {
			throw new Error(`File not found: ${url}`)
		}
	}
}
开发者ID:docscript,项目名称:docscript,代码行数:40,代码来源:server.ts


示例4:

import * as mime from 'mime-types';

mime.lookup('json');             // 'application/json'
mime.lookup('.md');              // 'text/x-markdown'
mime.lookup('file.html');        // 'text/html'
mime.lookup('folder/file.js');   // 'application/javascript'
mime.lookup('folder/.htaccess'); // false

mime.lookup('cats'); // false
mime.contentType('markdown');  // 'text/x-markdown; charset=utf-8'
mime.contentType('file.json'); // 'application/json; charset=utf-8'

// from a full path
mime.contentType('.json'); // 'application/json; charset=utf-8'

mime.extension('application/octet-stream'); // 'bin'

mime.charset('text/x-markdown'); // 'UTF-8'
开发者ID:AbraaoAlves,项目名称:DefinitelyTyped,代码行数:18,代码来源:mime-types-tests.ts


示例5: fileFilter

 static fileFilter(req: any, file, cb) {
   const ext = contentType(file.mimetype);
   const ext1 = file.mimetype;
   return cb(null, true);
 }
开发者ID:mbechev,项目名称:Feedback,代码行数:5,代码来源:file.service.ts



注:本文中的mime-types.contentType函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript mime-types.lookup函数代码示例发布时间:2022-05-25
下一篇:
TypeScript mime.lookup函数代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap