Skip to content

SendFileByUpload#

Test Postman

The method is intended for sending a file that is uploaded through a form (form-data).
In the response you will receive a link to the uploaded file.

The message is added to the sending queue.
The rate at which messages are sent from the queue is set by the message sending interval.

The method uses limits on the request rate per second.

The file storage period is 24 hours.

Request#

To send a file, you need to execute a request at:

POST
{{mediaUrl}}/waInstance{{idInstance}}/sendFileByUpload/{{apiTokenInstance}}

To get the mediaUrl, idInstance and apiTokenInstance request parameters, refer to the Before you start section.

Request parameters#

Parameter Type Required Description
chatId string Yes Chat identifier
file file Yes File being sent
fileName string No File name. It must contain the file extension.
You need to use UTF-8 encoding without BOM. For example: test.jpg
caption string No Caption under the file. The maximum caption length is 1024 characters.
quotedMessageId string No Identifier of the quoted message. When this parameter is filled in, the message will be sent quoting the specified chat message.
Quoting a message is possible only from the same chat the message is being sent to.
To send messages from another chat, the ForwardMessages method is used
Time to send a file

Files are sent in several stages:

  1. Getting the file
  2. A request to send the file to Telegram

The time to send a file depends on the file size, the file download speed and the processing of the file by Telegram. Depending on these factors, the time to send a file may vary from 1 to 20 seconds.

Response#

Response fields#

Field Type Description
idMessage string Identifier of the sent message
urlFile string Link to the file
quotedMessageId string Identifier of the quoted message
typingTime integer The time the typing notification is displayed in the correspondent's chat.
Takes a value in the range from 1000 to 20000 milliseconds (from 1 to 20 seconds)
typingType string Typing type. Possible values:
text - "typing..." (default)
record_voice_note - "recording a voice message..."
upload_voice_note - "sending a voice message..."
record_video_note - "recording a video message..".
upload_video_note - "sending a video message..."
record_video - "recording a video..."
upload_video - "sending a video..."
upload_photo - "sending a photo..."
upload_document - "sending a file..."
choose_sticker - "choosing a sticker..."
choose_location - "choosing a location..."
choose_contact - "choosing a contact..."

Response body example#

{
    "idMessage": "1769676078000",
    "urlFile": "https://mediaout-4100.storage.yandexcloud.net/41004000000/5eedf7a7878e691d093.jpg"
}

Errors#

For the list of errors common to all methods, see the Common errors section

HTTP code Error identifier Description
400 Bad Request
Validation failed
Validation error
400 file should not be empty The user sent an empty file. The file being uploaded must not be empty.

Code examples#

import requests

url = "{{mediaUrl}}/waInstance{{idInstance}}/sendFileByUpload/{{apiTokenInstance}}"

payload = {
    "chatId": "10000000",
    "caption": "Caption"
}
files = [
    ("file", ("window.jpg", open("C:/window.jpg","rb"),"image/jpeg"))
]
headers= {}

response = requests.post(url, data=payload, files=files)

print(response.text.encode('utf8'))
curl --location '{{mediaUrl}}/waInstance{{idInstance}}/sendFileByUpload/{{apiTokenInstance}}' \
--form 'chatId="10000000"' \
--form 'file=@"/Users/you/files/file.jpeg"' \
--form 'fileName="file.jpg"'
var restTemplate = new RestTemplate();
var requestUrl = new StringBuilder();
requestUrl
    .append({{mediaUrl}})
    .append("/waInstance").append({{idInstance}})
    .append("/sendFileByUpload/")
    .append({{apiTokenInstance}});

var headers = new HttpHeaders();
headers.setContentType(MediaType.MULTIPART_FORM_DATA);

var form = new LinkedMultiValueMap<>();
    form.add("chatId", "10000000");
    form.add("file", new FileSystemResource(new File("/Users/you/files/file.jpeg")));
    form.add("fileName", 1763115112.jpg);
    form.add("caption", "Caption");

var requestEntity = new HttpEntity<>(form, headers);

var response = restTemplate.exchange(requestUrl.toString(), HttpMethod.POST, requestEntity, String.class);
System.out.println(response);
var file = new File("/Users/user/Desktop/fileExample.jpeg");
var requestUrl = new StringBuilder();
requestUrl
    .append({{mediaUrl}})
    .append("/waInstance").append({{idInstance}})
    .append("/sendFileByUpload/")
    .append({{apiTokenInstance}});

var form = new HashMap<String, Object>();
    form.put("chatId", dto.getChatId());
    form.put("file", dto.getFile());
    form.put("fileName", dto.getFileName());
    form.put("caption", dto.getCaption());

var response = Unirest.post(requestUrl.toString())
    .fields(form)
    .asString();

System.out.println(response);