{
    "mode": "perldoc",
    "parameter": "MongoDB::GridFSBucket::UploadStream",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/perldoc/MongoDB%3A%3AGridFSBucket%3A%3AUploadStream/json",
    "generated": "2026-06-10T13:43:57Z",
    "synopsis": "# OO API\n$stream  = $bucket->openuploadstream(\"foo.txt\");\n$stream->print( $data );\n$stream->close;\n$id = $stream->id;\n# Tied handle API\n$fh = $stream->fh\nprint {$fh} $data;\nclose $fh;",
    "sections": {
        "NAME": {
            "content": "MongoDB::GridFSBucket::UploadStream - File handle abstraction for uploading\n",
            "subsections": []
        },
        "VERSION": {
            "content": "version v2.2.2\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "# OO API\n$stream  = $bucket->openuploadstream(\"foo.txt\");\n$stream->print( $data );\n$stream->close;\n$id = $stream->id;\n\n# Tied handle API\n$fh = $stream->fh\nprint {$fh} $data;\nclose $fh;\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "This class provides a file abstraction for uploading. You can stream data to an object of this\nclass via methods or via a tied-handle interface.\n\nWrites are buffered and sent in chunk-size units. When \"close\" is called, all data will be\nflushed to the GridFS Bucket and the newly created file will be visible.\n",
            "subsections": []
        },
        "ATTRIBUTES": {
            "content": "chunksizebytes\nThe number of bytes per chunk. Defaults to the \"chunksizebytes\" of the originating bucket\nobject.\n\nThis will be stored in the \"chunkSize\" field of the file document on a successful upload.\n\nfilename\nThe filename to store the file under. Note that filenames are NOT necessarily unique.\n\nThis will be stored in the \"filename\" field of the file document on a successful upload.\n\nmetadata\nAn optional hashref for storing arbitrary metadata about the file.\n\nIf defined, this will be stored in the \"metadata\" field of the file document on a successful\nupload.\n\ncontenttype (DEPRECATED)\nAn optional MIME type. This field should only be used for backwards compatibility with older\nGridFS implementations. New applications should store the content type in the metadata hash if\nneeded.\n\nIf defined, this will be stored in the \"contentType\" field of the file document on a successful\nupload.\n\naliases (DEPRECATED)\nAn optional array of aliases. This field should only be used for backwards compatibility with\nolder GridFS implementations. New applications should store aliases in the metadata hash if\nneeded.\n\nIf defined, this will be stored in the \"aliases\" field of the file document on a successful\nupload.\n",
            "subsections": []
        },
        "METHODS": {
            "content": "id\n$id = $stream->id;\n\nThe id of the file created by the stream. It will be stored in the \"id\" field of the file\ndocument on a successful upload. Some upload methods require specifying an id at upload time.\nDefaults to a newly-generated BSON::OID or BSON codec specific equivalent.\n\nfh\nmy $fh = $stream->fh;\nprint $fh, 'test data...';\nclose $fh\n\nReturns a new file handle tied to this instance of UploadStream that can be operated on with the\nbuilt-in functions \"print\", \"printf\", \"syswrite\", \"fileno\" and \"close\".\n\nImportant notes:\n\nAllowing one of these tied filehandles to fall out of scope will NOT cause close to be called.\nThis is due to the way tied file handles are implemented in Perl. For close to be called\nimplicitly, all tied filehandles and the original object must go out of scope.\n\nEach file handle retrieved this way is tied back to the same object, so calling close on\nmultiple tied file handles and/or the original object will have the same effect as calling close\non the original object multiple times.\n\nabort\n$stream->abort;\n\nAborts the upload by deleting any chunks already uploaded to the database and closing the\nstream.\n\nclose\n$filedoc = $stream->close;\n\nCloses the stream and flushes any remaining data to the database. Once this is done a file\ndocument is created in the GridFS bucket, making the uploaded file visible in subsequent queries\nor downloads.\n\nOn success, the file document hash reference is returned as a convenience.\n\nImportant notes:\n\n*   Calling close will also cause any tied file handles created for the stream to also close.\n\n*   \"close\" will be automatically called when a stream object is destroyed. When called this\nway, any errors thrown will not halt execution.\n\n*   Calling \"close\" repeatedly will warn.\n\nfileno\nif ( $stream->fileno ) { ... }\n\nWorks like the builtin \"fileno\", but it returns -1 if the stream is open and undef if closed.\n\nprint\n$stream->print(@data);\n\nWorks like the builtin \"print\".\n\nprintf\n$stream->printf($format, @data);\n\nWorks like the builtin \"printf\".\n\nsyswrite\n$stream->syswrite($buffer);\n$stream->syswrite($buffer, $length);\n$stream->syswrite($buffer, $length, $offset);\n\nWorks like the builtin \"syswrite\".\n",
            "subsections": []
        },
        "CAVEATS": {
            "content": "",
            "subsections": [
                {
                    "name": "Character encodings",
                    "content": "All the writer methods (e.g. \"print\", \"printf\", etc.) send a binary representation of the string\ninput provided (or generated in the case of \"printf\"). Unless you explicitly encode it to bytes,\nthis will be the internal representation of the string in the Perl interpreter. If you have\nASCII characters, it will already be bytes. If you have any characters above 0xff, it will be\nUTF-8 encoded codepoints. If you have characters between 0x80 and 0xff and not higher, you might\nhave either bytes or UTF-8 internally.\n\nYou are strongly encouraged to do your own character encoding with the Encode module or\nequivalent and upload only bytes to GridFS.\n"
                }
            ]
        },
        "AUTHORS": {
            "content": "*   David Golden <david@mongodb.com>\n\n*   Rassi <rassi@mongodb.com>\n\n*   Mike Friedman <friedo@friedo.com>\n\n*   Kristina Chodorow <k.chodorow@gmail.com>\n\n*   Florian Ragwitz <rafl@debian.org>\n",
            "subsections": []
        },
        "COPYRIGHT AND LICENSE": {
            "content": "This software is Copyright (c) 2020 by MongoDB, Inc.\n\nThis is free software, licensed under:\n\nThe Apache License, Version 2.0, January 2004\n",
            "subsections": []
        }
    },
    "summary": "MongoDB::GridFSBucket::UploadStream - File handle abstraction for uploading",
    "flags": [],
    "examples": [],
    "see_also": []
}