its just above the (Future start) , its a long data that is why i did not provided it here.
2 please tell me how to use payload as i dont have any idea
It's a String...how do you work with strings? What did you pass as data when you executed the function?
paste this same line as map of object not as string {
'image': 'image',
'productName': 'productName',
'productUnit': 'productUnit', // Provide default value for null
'barcode': 12245,
'id': " dataid",
'sellingPrice': 44.0,
'totalQuantity': 100.0,
'quantity': 1.0,
},
{
'image': 'image',
'productName': 'productName222',
'productUnit': 'productUnit', // Provide default value for null
'barcode': 456566565,
'id': " dataid",
'sellingPrice': 44.0,
'totalQuantity': 100.0,
'quantity': 1.0,
},
no...it's a string
should i use like this 'image': 'image',
'productName': 'productName222',
'productUnit': 'productUnit', // Provide default value for null
'barcode': 456566565,
'id': " dataid",
'sellingPrice': 44.0,
'totalQuantity': 100.0,
'quantity': 1.0,
Do you see what's wrong with this code:
final String payload = "";
payload['6439e7ae4abb3e14f2b1'];
You need to pass a valid JSON string and then parse it in your function. what you passed is not a valid JSON string.
should i use like this? , commented the previous line of codedart
//databaseId: payload['6439e7ae4abb3e14f2b1'],
//collectionId: payload['64444e34a0ce20bc4ac8'],
databaseId:'6439e7ae4abb3e14f2b1',
collectionId: '64444e34a0ce20bc4ac8',
'image': 'image',
'productName': 'productName',
'productUnit': 'productUnit', // Provide default value for null
'barcode': 12245,
'id': " dataid",
'sellingPrice': 44.0,
'totalQuantity': 100.0,
'quantity': 1.0,
},
{
'image': 'image',
'productName': 'productName222',
'productUnit': 'productUnit', // Provide default value for null
'barcode': 456566565,
'id': " dataid",
'sellingPrice': 44.0,
'totalQuantity': 100.0,
'quantity': 1.0,
},, APPWRITE_FUNCTION_USER_ID: 64386aeb90452ea0c185, APPWRITE_FUNCTION_JWT: eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VySWQiOiI2NDM4NmFlYjkwNDUyZWEwYzE4NSIsInNlc3Npb25JZCI6IjY0Mzg2YWViYTc0NzA1MjcwZGZjIiwiZXhwIjoxNjgzMzk5NzU5fQ.Qksi0AnCQ5BbScKXAV3Ef1LjDMoX2sZoLoDuFLepNyo}
{
'image': 'image',
'productName': 'productName',
'productUnit': 'productUnit', // Provide default value for null
'barcode': 12245,
'id': " dataid",
'sellingPrice': 44.0,
'totalQuantity': 100.0,
'quantity': 1.0,
},
{
'image': 'image',
'productName': 'productName222',
'productUnit': 'productUnit', // Provide default value for null
'barcode': 456566565,
'id': " dataid",
'sellingPrice': 44.0,
'totalQuantity': 100.0,
'quantity': 1.0,
},
AppwriteException: document_invalid_structure, Invalid document structure: Unknown attribute: "c1667f4f-d1aa-4310-933d-fd4244e30a29" (400)```
this is a log from appwrite after execution function
so you're passing something like this as batchData:
{
"some-uuid-id": {
"image": "",
"barcode": ""
// so on...
},
{"another-uuid-id": {
"image": "",
"barcode": ""
// so on...
}
}
This is not a valid document. have you gone through the basics about how to use the Appwrite databases api?
yse i have gone through the database api, and created document also, if i can not use uuid then what is best way to create batch document in a single response
If you really need to make 1 API request, you can try using graphql: https://appwrite.io/docs/graphql
Otherwise, it's much simpler to just call createDocument() for each document concurrently
ok, any example so that can perform batch operation.
Did you read what I linked?
yes, but dont want to use graphql.
So youre asking about how to execute create document concurrently?
yes, as i used for loop for creating document which is working fine but its taking time and every time its making new request for every new document creation.
also tried this but not working for long data and taking time dart
Future<void> uploadProducts(List<Map<String, dynamic>> products) async {
final futures = <Future>[];
for (final product in products) {
futures.add(Future(() async {
try {
final document = await database.createDocument(
databaseId: '6439e7ae4abb3e14f2b1',
collectionId: collectionId,
documentId: '',
data: product,
);
print('Product ${document.data['productName']} uploaded successfully.');
} catch (e) {
print('Error uploading product ${product['productName']}: $e');
}
}));
}
await Future.wait(futures);
print('All products uploaded successfully.');
}
Uh I don't think you create a future like Future(() async { ...})
NVM I guess you could...
It will still take time...the point is this will not wait for each document creation before proceeding to the next
ok
Recommended threads
- Weird permission failure
when creating an account I use following methods: ``` Future<void> register(String email, String password, String username) async { final user = await accoun...
- Flutter Android oAuth is no more working
I currently don't get the oAuth login to work in flutter android. it works on ios and on web. but when try to use it on Android, i get to the point where the ca...
- I'm experiencing a critical bug on Appwr...
Hey <@870607367597850624> team / support š I'm experiencing a critical bug on Appwrite Cloud that's blocking my production Flutter app. I've already filed GitH...