Skip to main content
Version: 4.0.0

📤 Upload Media File

Upload a media file to business account

Important Update in v4.0.0 – File Type

The file parameter type File has been updated to dynamic to ensure compatibility with web platforms.

  • Web platforms: Use List<int> (bytes)
  • Other platforms: Use File (file path)
import 'dart:io';

var upload = await whatsapp.uploadMediaFile(
file: File('sample_files/sample.png'),
fileType: 'image/png',
);

upload.getMediaId(); //10023589340434
paramtyperequireddescription
filedynamicyesFile or List<int>
fileTypeStringyesFile Type (ex. image/png)

Helper

getAutoFileType(filePath: fileUrl) - This methods help you automatically determine the file type.

var file_path = 'sample_files/sample.png'; //or full url
var upload = await whatsapp.uploadMediaFile(
file: File(file_path),
fileType: whatsapp.getAutoFileType(filePath: file_path), // ✅ auto-detect type
);
Cross Platforms Example
//Android, iOS, Windows, macOS, Linux
import 'dart:io';
var file_path = 'sample_files/sample.png';
final response = await whatsapp.uploadMediaFile(
file: File(file_path),
fileType: whatsapp.getAutoFileType(filePath: file_path), // ✅ auto-detect type
);
print('Media ID: ${response.getMediaId()}');
Supported Media Type

Please make sure you are using correct media types. Please find out supported media type here.

Some Tips (Native Platforms)

Here are some tips for media using image_picker Package and file_picker Package

For Image :-

final ImagePicker _picker = ImagePicker();
final XFile? image = await _picker.pickImage(source: ImageSource.gallery);

if (image != null) {
await whatsapp.uploadMediaFile(
file: File(image.path),
fileType: whatsapp.getAutoFileType(fileName: image.name), // ✅ auto-detect type
);
}

For Image, Audio, Video, Document or any file :-

FilePickerResult? result = await FilePicker.platform.pickFiles();

if (result != null) {
PlatformFile file = result.files.first;

await whatsapp.uploadMediaFile(
file: File(file.path!),
fileType: whatsapp.getAutoFileType(fileName: file.name), // ✅ auto-detect type
);
}

Media Return Methods