SendFileByUpload#
For the SendFileByUpload method, we recommend to use the media.green-api.com host
The method is aimed for sending a file uploaded by form (form-data). The message will be added to the send queue, in the response you will receive a link to the downloaded file. The rate at which messages are sent from the queue is managed by Message sending delay parameter.
The link is valid for 15 days.
The link can be reused using the SendFileByUrl method.
The minimum interval for sending messages from the queue using the SendFileByUpload method is 5 seconds.
Video, audio and image files available for viewing and listening to are sent as in native-mode WhatsApp. Documents are sent in the same way as in native-mode WhatsApp. Outgoing file type and send method is determined by the file extension. Description is only added to images and video.
The maximum size of outgoing files is 100 MB.
Request#
To send a file, you have to execute a request at:
POST https://media.green-api.com/waInstance{{idInstance}}/sendFileByUpload/{{apiTokenInstance}}
For idInstance
and apiTokenInstance
request parameters, refer to Before you start section.
Request parameters#
Parameter | Type | Mandatory | Description |
---|---|---|---|
chatId | string | Yes | Chat Id |
file | file | Yes | Outgoing file |
fileName | string | No | File name. Must contain file extension. |
caption | string | No | File caption. Caption added to video, images. |
quotedMessageId | string | No | Quoted message Id. If present, the message will be sent quoting the specified chat message. |
Request body example#
Request examples
import requests
url = "https://media.green-api.com/waInstance{{idInstance}}/sendFileByUpload/{{apiTokenInstance}}"
payload = {'chatId': '11001234567@c.us',
'caption': 'Описание'}
files = [
('file', ('window.jpg', open('C:/window.jpg','rb'),'image/jpeg'))
]
headers= {}
response = requests.request("POST", url, headers = headers, data = payload, files = files)
print(response.text.encode('utf8'))
curl --location 'https://media.green-api.com/waInstance{{idInstance}}/sendFileByUpload/{{apiTokenInstance}}' \
--form 'chatId="12345678910@c.us"' \
--form 'file=@"/Users/you/files/file.jpeg"' \
--form 'fileName="file.jpg"'
var restTemplate = new RestTemplate();
var requestUrl = new StringBuilder();
requestUrl
.append("https://media.greenapi.com")
.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", "12345678910@c.us");
form.add("file", new FileSystemResource(new File("/Users/you/files/file.jpeg")));
form.add("fileName", file.jpg);
form.add("caption", "Описание");
form.add("quotedMessageId", "BAE5F4886F6F2D05");
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("https://media.greenapi.com")
.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());
form.put("quotedMessageId", dto.getQuotedMessageId());
var response = Unirest.post(requestUrl.toString())
.fields(form)
.asString();
System.out.println(response);
program sendFileByUpload;
{$APPTYPE CONSOLE}
uses
System.SysUtils,
System.Classes, System.Net.HttpClient, System.Net.Mime, System.Net.URLClient, System.Net.HttpClientComponent;
var
HttpClient: TNetHTTPClient;
Response: IHTTPResponse;
FormData: TMultipartFormData;
EndpointURL, ID_INSTANCE, API_TOKEN_INSTANCE: string;
begin
ID_INSTANCE := '110100001';
API_TOKEN_INSTANCE := 'd75b3a66374942c5b3c019c698abc2067e151558acbd451234';
EndpointURL := 'https://media.green-api.com/waInstance' + ID_INSTANCE + '/sendFileByUpload/' + API_TOKEN_INSTANCE;
HttpClient := TNetHTTPClient.Create(nil);
FormData := TMultipartFormData.Create();
FormData.AddField('chatId', '71234567890@c.us');
FormData.AddField('caption', 'test');
FormData.AddFile('file', 'C:\tmp\bp.png');
try
Response := HTTPClient.Post(EndpointURL, FormData, nil);
if Response.StatusCode = 200 then
Writeln('[Response]: ' + Response.ContentAsString)
else
Writeln('[ERROR ' + IntToStr(Response.StatusCode) + ']:' + Response.StatusText + '' + Response.ContentAsString);
readln;
except
on E: Exception do
Writeln(E.ClassName, ': ', E.Message);
end;
HttpClient.Free;
FormData.Free;
end.
Response#
Response parameters#
Parameter | Type | Description |
---|---|---|
idMessage | string | Sent message Id |
urlFile | string | Link to file (link expires 15 days) |
Response body example#
{
"idMessage": "3EB0C767D097B7C7C030",
"urlFile": "https://sw-media-out.storage.yandexcloud.net/1101776123/c1aabd48-c1c2-49b1-8f2d-f575a41777be.jpg"
}
SendFileByUpload errors#
For a list of errors common to all methods, refer to Common errors section