How does Flutter web pick&upload any file type

Solution 1:

I have to change datatype

  1. Change input datatype to FilePickerResult
    FilePickerResult? picked = await FilePicker.platform.pickFiles();
  2. Do not use dart:html. Use dart:io
  3. Use MultipartFile.fromBytes since this is web. Reference
import 'package:file_picker/file_picker.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:dio/dio.dart';
import '../constants.dart';


Future<Response> uploadFile(
    FilePickerResult? picked,
    int currentMaxDownload,
    int currentExpiryOption,
    String? password
) async {
  print('Input Expire date in seconds from now: ${currentExpiryOption}');
  var utcNow = DateTime.now().toUtc();
  print('UTC Now: $utcNow');
  var trueExpiryDate = utcNow.add(Duration(seconds: currentExpiryOption));
  print('True expiry date: $trueExpiryDate');
  FormData formData = FormData.fromMap({
      "file": await MultipartFile.fromBytes(
      picked!.files.first.bytes as List<int>, filename: picked.files.first.name
    ),
    "max_downloads": currentMaxDownload,
    "expire_date": trueExpiryDate,
    "password": password
  });