MongoDB\GridFS\Bucket::getFileIdForStream()
Definição
Parâmetros
$stream
: recurso- O recurso de fluxo 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.
Erros/exceções
MongoDB\GridFS\Exception\CorruptFileException
if the file's
metadata or chunk documents contain unexpected or invalid data.
MongoDB\Exception\InvalidArgumentException
para erros relacionados à análise de parâmetros ou opções.
MongoDB\Driver\Exception\RuntimeException para outros erros no nível da extensão (por exemplo erros de conexão).
Exemplos
$bucket = (new MongoDB\Client)->test->selectGridFSBucket(); $stream = $bucket->openUploadStream('filename'); $id = $bucket->getFileIdForStream($stream); var_dump($id); fclose($stream);
A saída seria então semelhante a:
object(MongoDB\BSON\ObjectId)#3005 (1) { ["oid"]=> string(24) "5acfb37d7e21e83cdb3e1583" }