ファイルのアップロード
Misskey.pyはMisskeyのドライブにファイルをアップロードするためのメソッドを含んでいます。
- Misskey.drive_files_create(file: IO, folder_id: Optional[str] = None, name: Optional[str] = None, is_sensitive: bool = False, force: bool = False) dict [ソース]
Upload a file to the drive.
- Args:
file (
IO
): Assign a file stream. As an example, the one opened by theopen
function is included.folder_id (str, optional): Specify the folder ID.
name (str, optional): Specify the file name.
is_sensitive (bool, optional): Specify whether the file is sensitive.
force (bool, optional): Specify whether to overwrite the file if it already exists.
- Endpoint:
drive/files/create
- Returns:
dict: Returns the file information.
- Raises:
MisskeyAPIException: Raise if the API request fails.
ファイルをアップロードするには、ファイルストリーミングを開き、それをメソッドに渡します。
from misskey import Misskey
mk = Misskey("mk.example.com", i="xxxxxxxxxx")
with open("test.png", "rb") as f:
data = mk.drive_files_create(f)
print(data["id"]) # アップロードされたファイルのIDを表示
ファイルストリーミング以外指定してない場合は、名前はファイル名、フォルダはルートフォルダが指定されます。