Skip to content

file.download() should return the created file path #1041

@JosXa

Description

@JosXa

The current signature is as follows:

    def download(self, custom_path=None, out=None, timeout=None):
        """
        Download this file. By default, the file is saved in the current working directory with its
        original filename as reported by Telegram. If a :attr:`custom_path` is supplied, it will be
        saved to that path instead. If :attr:`out` is defined, the file contents will be saved to
        that object using the ``out.write`` method.
        ...

This some_file.download(...) method does not allow inspection on the saved file.
Since the download location is computed at runtime and dependant on the "original filename as reported by Telegram", you need to replicate the path calculations which were done in the method to have access to the downloaded file after calling it. So if you actually want to keep this original filename as reported by Telegram (for example because you cannot be sure about the file extension), there's no easy way to do that.

One-liners like
out_file = bot.get_file(update.effective_message.photo).download(custom_path="/some/path")
do_something_with(out_file)
are not possible.

Since the .download() method doesn't return any useful value at the moment, I suggest to let it return either a handle or the filepath to the created file.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy