MongoDB\GridFS\Bucket::getFileIdForStream()
定义
参数
$stream
: 资源- GridFS流资源。
返回值
与GridFS流关联的元数据文档的_id
字段。返回类型将取决于bucket的typeMap
选项。
错误/异常
MongoDB\GridFS\Exception\CorruptFileException
如果文件的元数据或块文档包含意外或无效数据。
MongoDB\Exception\InvalidArgumentException
与参数或选项解析相关的错误。
MongoDB\Driver\Exception\RuntimeException 对于扩展级别(例如连接错误)的其他错误。
示例
$bucket = (new MongoDB\Client)->test->selectGridFSBucket(); $stream = $bucket->openUploadStream('filename'); $id = $bucket->getFileIdForStream($stream); var_dump($id); fclose($stream);
输出结果将类似于
object(MongoDB\BSON\ObjectId)#3005 (1) { ["oid"]=> string(24) "5acfb37d7e21e83cdb3e1583" }