pocketbase / dart-sdk

PocketBase Dart SDK
https://pub.dev/packages/pocketbase
MIT License
511 stars 51 forks source link

Weird create function with body and files in Dart SDK #53

Closed RonByRonn closed 7 months ago

RonByRonn commented 7 months ago

I am trying to create record with data and files (like example in https://pocketbase.io/docs/files-handling/)

here is my code:

final files = await Future.wait(
  images.map(
    (XFile image) => MultipartFile.fromPath(
      'images',
      image.path,
      filename: 'abc.jpg',
    ),
  ),
);

final body = <String, dynamic>{
  "text": "123",
};

final record = await pb.collection('collection').create(
  files: files,
  body: body,
);

but when I run above code, only files are successfully uploaded to DB and no body data is reflected in DB. if I comment out files like this:

final record = await pb.collection('collection').create(
  // files: files,
  body: body,
);

then body is successfully uploaded to DB.

why is this happening and how can I solve this? I can't find any difference between my code and example in https://pocketbase.io/docs/files-handling/

thank you

ganigeorgiev commented 7 months ago

It works correctly for me and I'm not able to reproduce it locally with PocketBase v0.22.4 and PocketBase Dart SDK v0.18.1.

pb.collection("example").create(
  files: [
    http.MultipartFile.fromString(
      'file', // the name of the file field
      'example content...',
      filename: 'example_document.txt',
    ),
  ],
  body: {
    "title": "test",
  },
);

Note that PocketBase Dart SDK v0.18+ is compatible only with PocketBase v0.21+ (see the CHANGELOG).

If you are still not able to resolve it, feel free to provide more details about your testing environment and/or create a minimal reproducible repo and I'll try to investigate it further.

mttschltz commented 7 months ago

Note that PocketBase Dart SDK v0.18+ is compatible only with PocketBase v0.21+ (see the CHANGELOG).

I had a similar problem. Upgrading the backend fixed it 👍

I setup my Dart project a few weeks after my backend project, which is probably why I didn't check the changelog or consider the versions might be incompatible.