2020-04-12 18:15:33 +12:00
|
|
|
# Examples
|
|
|
|
|
|
|
|
Init your Appwrite client:
|
|
|
|
|
|
|
|
```dart
|
|
|
|
Client client = Client();
|
|
|
|
|
|
|
|
client
|
|
|
|
.setEndpoint('https://localhost/v1') // Your Appwrite Endpoint
|
|
|
|
.setProject('5e8cf4f46b5e8') // Your project ID
|
2020-04-12 19:47:58 +12:00
|
|
|
.setSelfSigned() // Remove in production
|
2020-04-12 18:15:33 +12:00
|
|
|
;
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
Create a new user and session:
|
|
|
|
|
|
|
|
```dart
|
2020-04-12 22:57:28 +12:00
|
|
|
Account account = Account(client);
|
2020-04-12 18:15:33 +12:00
|
|
|
|
2022-01-05 01:33:27 +13:00
|
|
|
Response user = await account.create(userId: '[USER_ID]', email: 'me@appwrite.io', password: 'password', name: 'My Name');
|
2020-04-12 18:15:33 +12:00
|
|
|
|
2020-04-12 22:57:28 +12:00
|
|
|
Response session = await account.createSession(email: 'me@appwrite.io', password: 'password');
|
2020-04-12 18:15:33 +12:00
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
Fetch user profile:
|
|
|
|
|
|
|
|
```dart
|
|
|
|
Account account = Account(client);
|
|
|
|
|
|
|
|
Response profile = await account.get();
|
|
|
|
```
|
|
|
|
|
|
|
|
Upload File:
|
|
|
|
|
|
|
|
```dart
|
|
|
|
Storage storage = Storage(client);
|
|
|
|
|
2022-03-03 20:44:38 +13:00
|
|
|
late InputFile file;
|
|
|
|
|
|
|
|
if(kIsWeb) {
|
|
|
|
file = InputFile(file: MultipartFile.fromFile('./path-to-file/image.jpg', filename: 'image.jpg'));
|
|
|
|
} else {
|
|
|
|
file = InputFile(path: './path-to-file/image.jpg', fileName: 'image.jpg');
|
|
|
|
}
|
2020-04-12 18:15:33 +12:00
|
|
|
|
|
|
|
storage.createFile(
|
2022-03-03 20:44:38 +13:00
|
|
|
bucketId: '[BUCKET_ID]',
|
|
|
|
fileId: '[FILE_ID]', // use 'unique()' to automatically generate a unique ID
|
2020-04-12 18:15:33 +12:00
|
|
|
file: file,
|
2021-06-12 06:23:16 +12:00
|
|
|
read: ['role:all'],
|
2020-04-12 18:15:33 +12:00
|
|
|
write: []
|
|
|
|
)
|
|
|
|
.then((response) {
|
|
|
|
print(response); // File uploaded!
|
|
|
|
})
|
|
|
|
.catchError((error) {
|
|
|
|
print(error.response);
|
|
|
|
});
|
|
|
|
```
|
|
|
|
|
|
|
|
All examples and API features are available at the [official Appwrite docs](https://appwrite.io/docs)
|