Answer the question
In order to leave comments, you need to log in
Why is empty file uploaded to python vk_api conversation?
I'm trying to upload a local file to a conversation. I tried both through the built-in vk_api methods , and the method from the documentation. Here is the code for the latter:
method = vk.docs.getMessagesUploadServer(peer_id=event.message.peer_id)["upload_url"]
file = requests.post(method, files={'file': open(f'data/{filename}', "rb")})
if file.status_code == 200:
file = file.json()['file']
uploaded = vk.docs.save(file=file)
vk.messages.send(
key=(bot_config['key']),
server=(bot_config['server']),
ts=(bot_config['ts']),
random_id=get_random_id(),
message=f' {first_name} {last_name}\n\n{text}',
chat_id=event.chat_id,
attachment=f"doc{uploaded['doc']['owner_id']}_{uploaded['doc']['id']}")
else:
answer(' Не получилось загрузить файл. Попробуйте обновить данные.', event.chat_id)
Answer the question
In order to leave comments, you need to log in
It helped me to replace the method with docs.getWallUploadServer and the file was uploaded to the group files, but at the same time it became possible to download it in the conversation (I have Node js)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question