Back

Error: converting object to an encodable object failed: instance of DateTime

  • 0
  • Flutter
youngmarc#5963 | melon.ooo
10 May, 2023, 14:22

hello guys can someone help me out. i keep getting this error trying to update a database in flutter: 'converting object to an encodable object failed: instance of DateTime'. i am using the appwrite cloud.

TL;DR
The user is encountering an error when trying to update a database in Flutter using the Appwrite cloud. The error message states "converting object to an encodable object failed: instance of DateTime". The user has tried using the http package and the Appwrite SDK but is still experiencing slow download times. Another user suggests converting DateTime variables to milliseconds and saving them as integer attributes in Appwrite as a workaround. No solution is provided for the error message.
Drake
10 May, 2023, 17:49

It would help if you shared more detail like your code, the exact error, and your data

youngmarc#5963 | melon.ooo
11 May, 2023, 06:29

Thanks, i have been able to find a work around by turning my DateTime variables into milliseconds and saving them as integer attribute on appwrite .

Drake
11 May, 2023, 06:33

Your problem was probably a dart problem since you can't jsonEncode() some types like DateTime. If you have a date time attribute in appwrite, you would convert it by calling d.toUtc().toIso8601String() or something like that

youngmarc#5963 | melon.ooo
28 May, 2023, 02:01

tried that, didn't work.

Drake
28 May, 2023, 02:16

So what's the problem now?

youngmarc#5963 | melon.ooo
28 May, 2023, 02:20

the problem now: i am using the http package in flutter to get video files from appwrite cloud storage, but the wait time is too long compared to when i use firebase. is there something i need to do?. here is what my function looks like

youngmarc#5963 | melon.ooo
28 May, 2023, 02:21

` Future<void> _initializeVideo() async { debugPrint('----->STARTING VIDEO INITIALIZER'); final String videoFileName = getAppwriteFileName(widget.videoUrl); final String cachePath = await getCachePath(); final File videoFile = File('$cachePath/$videoFileName');

TypeScript
try {
  if (videoFile.existsSync()) {
    debugPrint('----->VIDEO ALREADY EXISTS');
    _controller = VideoPlayerController.file(videoFile);
  } else {
    debugPrint('----->DOWNLOADING VIDEO');
    var headers = {
      "Content-Type": "video/mp4",
      "X-Appwrite-Project": "my project id",
      "X-Appwrite-Key":
          "my api key"
    };
    final http.Response response =
        await http.get(Uri.parse(widget.videoUrl), headers: headers);
    await videoFile.create(recursive: true);
    await videoFile.writeAsBytes(response.bodyBytes);
    debugPrint('----->SETTING CONTROLLER TO FILE');
    debugPrint('-----> ${videoFile.absolute}');
    _controller = VideoPlayerController.file(videoFile);
  }

  _initializeVideoFuture = _controller.initialize().then((value) {
    debugPrint('----->INITIALIZING VIDEO');
    setState(() {
      _controller.setLooping(true);
      isLandscape = isLandscapeVideo();
      isready = true;
    });
  });
} catch (error) {
  debugPrint('----->Error initializing video: $error');
  // Handle the error, e.g., display an error message to the user
}

}`

Drake
28 May, 2023, 04:26

This isn't in your flutter app is it?

Drake
28 May, 2023, 04:26

Why are you using http package for this?

youngmarc#5963 | melon.ooo
29 May, 2023, 13:23

i was trying to make it a progressive download and playback that's why i was using the http package. but i failed and i am now using the appwrite sdk function storage.getFileDownload but its still as slow as using the http package 👀

youngmarc#5963 | melon.ooo
29 May, 2023, 13:24

do you know how i can implement progressive video download and playback in flutter?

Drake
29 May, 2023, 14:58

You can try to put the URL into your player.

There are a couple of factors at play here.

  1. There could be network latency due to where the cloud server is in relation to where you are.
  2. If you try to download the entire file and then load that into your player, the user has to wait for the full download. If you put the URL into the player, the player will request chunks of the file and then start playing when some chunks are available while still downloading the rest.
Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more