Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

【提议】支持文件的上传和读取 #60

Open
Agnes4m opened this issue Jul 15, 2023 · 5 comments
Open

【提议】支持文件的上传和读取 #60

Agnes4m opened this issue Jul 15, 2023 · 5 comments

Comments

@Agnes4m
Copy link

Agnes4m commented Jul 15, 2023

文件的上传和下载,也是通讯中很普遍的功能,希望可以实现这个功能辣

@felinae98
Copy link
Collaborator

@MeetWq @lgc2333 @ssttkkl 大家调研一下自己负责的 adapter 有无发送文件的功能?并且是用什么样的接口实现的

@lgc2333
Copy link
Member

lgc2333 commented Mar 10, 2024

抄抄 alc 吧(

@lgc2333
Copy link
Member

lgc2333 commented Mar 10, 2024

节选自官方文档(点击展开)

InputFile

This object represents the contents of a file to be uploaded. Must be posted using multipart/form-data in the usual way that files are uploaded via the browser.

Sending files

There are three ways to send files (photos, stickers, audio, media, etc.):

If the file is already stored somewhere on the Telegram servers, you don't need to reupload it: each file object has a file_id field, simply pass this file_id as a parameter instead of uploading. There are no limits for files sent this way.
Provide Telegram with an HTTP URL for the file to be sent. Telegram will download and send the file. 5 MB max size for photos and 20 MB max for other types of content.
Post the file using multipart/form-data in the usual way that files are uploaded via the browser. 10 MB max size for photos, 50 MB for other files.

Sending by file_id

It is not possible to change the file type when resending by file_id. I.e. a video can't be sent as a photo, a photo can't be sent as a document, etc.
It is not possible to resend thumbnails.
Resending a photo by file_id will send all of its sizes.
file_id is unique for each individual bot and can't be transferred from one bot to another.
file_id uniquely identifies a file, but a file can have different valid file_ids even for the same bot.

Sending by URL

When sending by URL the target file must have the correct MIME type (e.g., audio/mpeg for sendAudio, etc.).
In sendDocument, sending by URL will currently only work for GIF, PDF and ZIP files.
To use sendVoice, the file must have the type audio/ogg and be no more than 1MB in size. 1-20MB voice notes will be sent as files.
Other configurations may work but we can't guarantee that they will.

@MeetWq
Copy link
Contributor

MeetWq commented Mar 11, 2024

飞书机器人可以 上传文件下载文件,上传文件返回 file_key,下载文件需要 file_key

上传文件需要的必填参数:

  • file_type: 文件类型,如 mp4
  • file_name: 带后缀的文件名
  • file: 文件二进制内容

可选参数:

  • duration: 视频、音频文件的时长

@ssttkkl
Copy link
Contributor

ssttkkl commented Mar 11, 2024

https://github.com/Tian-que/nonebot-adapter-kaiheila/blob/376d074b6a8915c0b963d0f009cc4edd0f05b340/nonebot/adapters/kaiheila/message.py#L140

kook的发送文件,我直接贴适配器接口好了(
file_key需要事先调接口上传生成,local_file是用来方便用户直接上传本地文件用的

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants