import { Client, Databases, ID } from "appwrite";
const client = new Client()
.setEndpoint('https://cloud.appwrite.io/v1')
.setProject('<PROJECT_ID>');
const databases = new Databases(client);
const id = Date.now(); //this does not work, error recieved is shown after code ends
const promise = databases.createDocument(
'[DATABASE_ID]',
'[COLLECTION_ID]',
id,
data
);
promise.then(function (response) {
console.log(response);
}, function (error) {
console.log(error);
});
error: AppwriteException: Invalid documentId param: Parameter must contain at most 36 chars. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char
But the same method works in upload file:
import { Client, Storage } from "appwrite";
const client = new Client();
const storage = new Storage(client);
client
.setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint
.setProject('5df5acd0d48c2') // Your project ID
;
const id = Date.now() //this works and file is created
const promise = storage.createFile('[BUCKET_ID]', id, document.getElementById('uploader').files[0]);
promise.then(function (response) {
console.log(response); // Success
}, function (error) {
console.log(error); // Failure
});
Cannot create documents using custom id in web (works if in console)
Date.now() returns an int, and the document ID needs to be a string. so you can do something like const id = Date.now().toString()
You can review the docs here to see the properties and their type expectancies here: https://appwrite.io/docs/references/cloud/models/document
Recommended threads
- is `account.get()` safe to be used in th...
I want to user's `id` for authentication. However, a while ago I was told in this server not to use `account.get()` and instead add user preferences for that us...
- Appwrite console is too heavy
The Appwrite console is too heavy And all of my services broken Any support , please
- Usage of the new Client() and dealing wi...
Hey guys, just a quick one - we had some web traffic the other day and it ended up bombing out - To put in perspective of how the app works, we have a Nuxt Ap...