當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript mongodb.GridFSBucket類代碼示例

本文整理匯總了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;未經允許,請勿轉載。