Rank 3: Container
trying to create bulk product document, using cloud function, sending product data as json to payload
Votes
0
Replies
24
Participants
Unknown
Messages
25
Rank 3: Container
trying to create bulk product document, using cloud function, sending product data as json to payload
Rank 3: Container
product data is creation if there is less product but if there is lots of product then its giving this error, here is my code if you want to check Future<void> uploadProducts(List<Map<String, dynamic>> products) async { String payloadString = json.encode({"hallelujah":products}); print(payloadString); Future result = functions.createExecution( functionId: 'upload', data: payloadString, );
How long ??
And can you share the uploadFunction on what you are trying to do??
Rank 3: Container
more the 10k products
Rank 3: Container
here in my function ```Future start(final req, final res) async {
final client = Client();
final db = Databases(client);
final payload = !req.payload?.isEmpty ? jsonDecode(req.payload) : 'No payload provided. Add custom data when executing function.';
if (req.variables['APPWRITE_FUNCTION_ENDPOINT'] == null ||
req.variables['APPWRITE_FUNCTION_API_KEY'] == null) {
print("Environment variables are not set. Function cannot use Appwrite SDK.");
} else {
print(payload["hallelujah"]);
client
.setEndpoint(req.variables['APPWRITE_FUNCTION_ENDPOINT'])
.setProject(req.variables['APPWRITE_FUNCTION_PROJECT_ID'])
.setKey(req.variables['APPWRITE_FUNCTION_API_KEY'])
.setSelfSigned(status: true);
print(req.variables);
try{
final productData = payload['hallelujah'];
for(var product in productData){
await db.createDocument(
databaseId:'6439e7ae4abb3e14f2b1',
collectionId: '64444e34a0ce20bc4ac8',
documentId: "",
data: product
);
}
}catch(e){
print(e.toString());
}
}
res.json({
'payload': payload,
'areDevelopersAwesome': true,
});
}
so this should fail cause the documentId is empty and it needs an Id
Secondly the error states that the maximum string size it can accept is around 8192 chars and yours would be certainly way more than that
One more thing since , you are creating bunch of documents why not use the client side function instead of going through a cloud function?
Rank 3: Container
document id is empty for autogeneration of doc id
Rank 3: Container
how to use client side function
You need to use Id.unique() for that for autogeneration
Rank 3: Container
but its creating doc id,
I didn't understand what you are trying to say
Rank 5: Hypervisor
there is feature req for it
https://github.com/appwrite/appwrite/issues/3051
Rank 5: Hypervisor
what you can do it create document concurrenlty, like 100 doc parllerly
Rank 5: Hypervisor
Rank 5: Hypervisor
should take mostly 1mins max
Rank 5: Hypervisor
or possibly 100-110 sec, 10000/100 = 100 ( my math xD)
Rank 3: Container
but for this i have to upload the file then retrieve the data
Rank 5: Hypervisor
no no, for reach document creation you automatically does get document response object
Rank 3: Container
i tried this using for loop which is working but taking too much time ```
for (final product in products) {
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');
}
}```
Rank 5: Hypervisor
yap pls don't use loop, try to make concurrent request
Rank 5: Hypervisor
...
Rank 3: Container
ok let me check and try .
Rank 5: Hypervisor
that is python code btw