nonebot-plugin-send-anything-anywhere icon indicating copy to clipboard operation
nonebot-plugin-send-anything-anywhere copied to clipboard

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

Open Agnes4m opened this issue 1 year ago • 5 comments

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

Agnes4m avatar Jul 15 '23 17:07 Agnes4m

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

felinae98 avatar Mar 10 '24 14:03 felinae98

抄抄 alc 吧(

lgc2333 avatar Mar 10 '24 19:03 lgc2333

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

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.

lgc2333 avatar Mar 10 '24 19:03 lgc2333

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

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

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

可选参数:

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

MeetWq avatar Mar 11 '24 01:03 MeetWq

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

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

ssttkkl avatar Mar 11 '24 14:03 ssttkkl