本文整理汇总了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();
}
示例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 + ")"
);
});
});
示例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}`)
}
}
}
示例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'
示例5: fileFilter
static fileFilter(req: any, file, cb) {
const ext = contentType(file.mimetype);
const ext1 = file.mimetype;
return cb(null, true);
}