本文整理汇总了TypeScript中mongodb.GridFSBucket类的典型用法代码示例。如果您正苦于以下问题:TypeScript GridFSBucket类的具体用法?TypeScript GridFSBucket怎么用?TypeScript GridFSBucket使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了GridFSBucket类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。
示例1: GridFSBucket
.then(client => {
const bucket = new GridFSBucket(client.db());
bucket.delete(filename, err => {
if (err) return void reject(err);
resolve();
});
})
开发者ID:zaidka,项目名称:genieacs,代码行数:7,代码来源:db.ts
示例2: GridFSBucket
db.filesCollection.findOne({ _id: filename }, (err, file) => {
if (err) {
response.writeHead(500, { Connection: "close" });
response.end(`${err.name}: ${err.message}`);
throw err;
}
if (!file) {
response.writeHead(404);
response.end();
return;
}
response.writeHead(200, {
"Content-Type": file.contentType || "application/octet-stream",
"Content-Length": file.length
});
const bucket = new GridFSBucket(db.client.db());
const downloadStream = bucket.openDownloadStreamByName(filename);
downloadStream.pipe(response);
});
开发者ID:zaidka,项目名称:genieacs,代码行数:22,代码来源:fs.ts
示例3: getBody
//.........这里部分代码省略.........
{ _id: `${deviceId}:task_${taskId}` },
err => {
if (err) return void throwError(err, response);
cache.del(`${deviceId}_tasks_faults_operations`, err => {
if (err) return void throwError(err, response);
response.writeHead(200);
response.end();
});
}
);
}
);
} else {
response.writeHead(405, { Allow: "POST" });
response.end("405 Method Not Allowed");
}
} else {
response.writeHead(404);
response.end();
}
} else if (FILES_REGEX.test(urlParts.pathname)) {
const filename = querystring.unescape(
FILES_REGEX.exec(urlParts.pathname)[1]
);
if (request.method === "PUT") {
const metadata = {
fileType: request.headers.filetype,
oui: request.headers.oui,
productClass: request.headers.productclass,
version: request.headers.version
};
const bucket = new mongodb.GridFSBucket(db.client.db());
const uploadStream = bucket.openUploadStreamWithId(filename, filename, {
metadata: metadata
});
uploadStream.on("error", err => {
throwError(err, response);
});
uploadStream.end(body, () => {
response.writeHead(201);
response.end();
});
} else if (request.method === "DELETE") {
const bucket = new mongodb.GridFSBucket(db.client.db());
bucket.delete((filename as unknown) as mongodb.ObjectId, err => {
if (err) return void throwError(err, response);
response.writeHead(200);
response.end();
});
} else {
response.writeHead(405, { Allow: "PUT, DELETE" });
response.end("405 Method Not Allowed");
}
} else if (PING_REGEX.test(urlParts.pathname)) {
const host = querystring.unescape(PING_REGEX.exec(urlParts.pathname)[1]);
exec(`ping -w 1 -i 0.2 -c 3 ${host}`, (err, stdout) => {
if (err) {
response.writeHead(404, { "Cache-Control": "no-cache" });
response.end(`${err.name}: ${err.message}`);
return;
}
开发者ID:zaidka,项目名称:genieacs,代码行数:67,代码来源:nbi.ts
注:本文中的mongodb.GridFSBucket类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论