MongoDB\GridFS\Bucket::getFileIdForStream()
定义
参数
$stream
:资源- GridFS 流资源。
Return Values
The _id
field of the metadata document associated with the GridFS stream.
The return type will depend on the bucket's typeMap
option.
错误/异常
MongoDB\GridFS\Exception\CorruptFileException
if the file's
metadata or chunk documents contain unexpected or invalid data.
MongoDB\Exception\InvalidArgumentException
表示与参数或选项解析相关的错误。
MongoDB\ 驱动程序\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" }