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
- Function domain not available
Hello, even tho in docs you clearly describe that every function has its domain, I can not see it anywhere in any of my projects. How do I reveal the url of th...
- Paused project can't activate
I have failed to reactivate one my projects which had been paused
- after using the coding agents its code b...
can anybody suggest me an ai tool that i can use to create the system desgins without the suggestion things because it at last create a mess