From ea11598628fcaae7b76f5ccbe212d9ad5912c638 Mon Sep 17 00:00:00 2001 From: haimantika mitra <32809211+Haimantika@users.noreply.github.com> Date: Tue, 19 Sep 2023 10:56:11 +0000 Subject: [PATCH 01/16] Added more methods to upload and download --- .../storage/upload-download/+page.markdoc | 325 +++++++++++++++++- 1 file changed, 324 insertions(+), 1 deletion(-) diff --git a/src/routes/docs/products/storage/upload-download/+page.markdoc b/src/routes/docs/products/storage/upload-download/+page.markdoc index 9adb3c8c67..93634cca58 100644 --- a/src/routes/docs/products/storage/upload-download/+page.markdoc +++ b/src/routes/docs/products/storage/upload-download/+page.markdoc @@ -213,7 +213,7 @@ The Appwrite Python SDK expects an `InputFile` class for file inputs. | ------------------------------------------ | ------------------------------------------------------------ | | `InputFile.from_path(path)` | Used to upload files from a provided path. | | `InputFile.from_bytes(bytes)` | Used to upload files from an array of bytes. | -{% /tabsitem %} +{% /tabsitem %} {% tabsitem #ruby title="Ruby" %} The Appwrite Ruby SDK expects an `InputFile` class for file inputs. @@ -383,4 +383,327 @@ class MainActivity : AppCompatActivity() { } ``` ```dart +{% /multicode %} + +## Get File {% #get-file %} +To get a file, use the `getFile` method. + +{% multicode %} +```js +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 promise = storage.getFile('[BUCKET_ID]', '[FILE_ID]'); + +promise.then(function (response) { + console.log(response); // Success +}, function (error) { + console.log(error); // Failure +}); +``` +```dart +import 'package:appwrite/appwrite.dart'; + +void main() { // Init SDK + Client client = Client(); + Storage storage = Storage(client); + + client + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint + .setProject('5df5acd0d48c2') // Your project ID + ; + // downloading file + Future result = storage.getFile( + bucketId: '[BUCKET_ID]', + fileId: '[FILE_ID]', + ).then((bytes) { + final file = File('path_to_file/filename.ext'); + file.writeAsBytesSync(bytes) + }).catchError((error) { + print(error.response); + }) +} + +//displaying image preview +FutureBuilder( + future: storage.getFile( + bucketId: '[BUCKET_ID]', + fileId: '[FILE_ID]', + ), //works for both public file and private file, for private files you need to be logged in + builder: (context, snapshot) { + return snapshot.hasData && snapshot.data != null + ? Image.memory( + snapshot.data, + ) + : CircularProgressIndicator(); + }, +); +``` +```swift +import Appwrite + +func main() async throws { + let client = Client() + .setEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + .setProject("5df5acd0d48c2") // Your project ID + let storage = Storage(client) + let byteBuffer = try await storage.getFile( + bucketId: "[BUCKET_ID]", + fileId: "[FILE_ID]" + ) + + print(String(describing: byteBuffer) +} +``` +```kotlin +import androidx.appcompat.app.AppCompatActivity +import android.os.Bundle +import kotlinx.coroutines.GlobalScope +import kotlinx.coroutines.launch +import io.appwrite.Client +import io.appwrite.services.Storage + +class MainActivity : AppCompatActivity() { + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_main) + + val client = Client(applicationContext) + .setEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + .setProject("5df5acd0d48c2") // Your project ID + + val storage = Storage(client) + + GlobalScope.launch { + val result = storage.getFile( + bucketId = "[BUCKET_ID]", + fileId = "[FILE_ID]" + ) + println(result); // Resource URL + } + } +} +``` +```dart +{% /multicode %} + +## Get File Preview {% #get-file-preview %} +To get a file preview image , use the `getFilePreview` method. + +{% multicode %} +```js +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 result = storage.getFilePreview('[BUCKET_ID]', '[FILE_ID]'); + +console.log(result); // Resource URL +``` +```dart +import 'package:appwrite/appwrite.dart'; + +void main() { // Init SDK + Client client = Client(); + Storage storage = Storage(client); + + client + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint + .setProject('5df5acd0d48c2') // Your project ID + ; + // downloading file + Future result = storage.getFilePreview( + bucketId: '[BUCKET_ID]', + fileId: '[FILE_ID]', + ).then((bytes) { + final file = File('path_to_file/filename.ext'); + file.writeAsBytesSync(bytes) + }).catchError((error) { + print(error.response); + }) +} + +//displaying image preview +FutureBuilder( + future: storage.getFilePreview( + bucketId: '[BUCKET_ID]', + fileId: '[FILE_ID]', + ), //works for both public file and private file, for private files you need to be logged in + builder: (context, snapshot) { + return snapshot.hasData && snapshot.data != null + ? Image.memory( + snapshot.data, + ) + : CircularProgressIndicator(); + }, +); +``` +```swift +import Appwrite + +func main() async throws { + let client = Client() + .setEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + .setProject("5df5acd0d48c2") // Your project ID + let storage = Storage(client) + let byteBuffer = try await storage.getFilePreview( + bucketId: "[BUCKET_ID]", + fileId: "[FILE_ID]" + ) + + print(String(describing: byteBuffer) +} +``` +```kotlin +import androidx.appcompat.app.AppCompatActivity +import android.os.Bundle +import kotlinx.coroutines.GlobalScope +import kotlinx.coroutines.launch +import io.appwrite.Client +import io.appwrite.services.Storage + +class MainActivity : AppCompatActivity() { + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_main) + + val client = Client(applicationContext) + .setEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + .setProject("5df5acd0d48c2") // Your project ID + + val storage = Storage(client) + + GlobalScope.launch { + val result = storage.getFilePreview( + bucketId = "[BUCKET_ID]", + fileId = "[FILE_ID]" + ) + println(result); // Resource URL + } + } +} +``` +```dart +{% /multicode %} + +## View File {% #view-file%} + +To view a file, use the `getFileView` method. + +{% multicode %} +```js +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 result = storage.getFileView('[BUCKET_ID]', '[FILE_ID]'); + +console.log(result); // Resource URL +``` +```dart +import 'package:appwrite/appwrite.dart'; + +void main() { // Init SDK + Client client = Client(); + Storage storage = Storage(client); + + client + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint + .setProject('5df5acd0d48c2') // Your project ID + ; + // downloading file + Future result = storage.getFileView( + bucketId: '[BUCKET_ID]', + fileId: '[FILE_ID]', + ).then((bytes) { + final file = File('path_to_file/filename.ext'); + file.writeAsBytesSync(bytes) + }).catchError((error) { + print(error.response); + }) +} + +//displaying image preview +FutureBuilder( + future: storage.getFileView( + bucketId: '[BUCKET_ID]', + fileId: '[FILE_ID]', + ), //works for both public file and private file, for private files you need to be logged in + builder: (context, snapshot) { + return snapshot.hasData && snapshot.data != null + ? Image.memory( + snapshot.data, + ) + : CircularProgressIndicator(); + }, +); +``` +```swift +import Appwrite + +func main() async throws { + let client = Client() + .setEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + .setProject("5df5acd0d48c2") // Your project ID + let storage = Storage(client) + let byteBuffer = try await storage.getFileView( + bucketId: "[BUCKET_ID]", + fileId: "[FILE_ID]" + ) + + print(String(describing: byteBuffer) +} +``` +```kotlin +import androidx.appcompat.app.AppCompatActivity +import android.os.Bundle +import kotlinx.coroutines.GlobalScope +import kotlinx.coroutines.launch +import io.appwrite.Client +import io.appwrite.services.Storage + +class MainActivity : AppCompatActivity() { + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_main) + + val client = Client(applicationContext) + .setEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + .setProject("5df5acd0d48c2") // Your project ID + + val storage = Storage(client) + + GlobalScope.launch { + val result = storage.getFileView( + bucketId = "[BUCKET_ID]", + fileId = "[FILE_ID]" + ) + println(result); // Resource URL + } + } +} +``` +```dart {% /multicode %} \ No newline at end of file From d3b5b43459a9d53b7b2ccdd1302a5dbdc09448cd Mon Sep 17 00:00:00 2001 From: haimantika mitra <32809211+Haimantika@users.noreply.github.com> Date: Tue, 19 Sep 2023 20:00:45 +0530 Subject: [PATCH 02/16] Made changes --- src/routes/docs/products/storage/upload-download/+page.markdoc | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/routes/docs/products/storage/upload-download/+page.markdoc b/src/routes/docs/products/storage/upload-download/+page.markdoc index 93634cca58..0be75dc8f0 100644 --- a/src/routes/docs/products/storage/upload-download/+page.markdoc +++ b/src/routes/docs/products/storage/upload-download/+page.markdoc @@ -383,7 +383,6 @@ class MainActivity : AppCompatActivity() { } ``` ```dart -{% /multicode %} ## Get File {% #get-file %} To get a file, use the `getFile` method. @@ -705,5 +704,4 @@ class MainActivity : AppCompatActivity() { } } ``` -```dart {% /multicode %} \ No newline at end of file From b28fe71caadc3371805e48bc2586c46f015e49fc Mon Sep 17 00:00:00 2001 From: Arman Date: Thu, 21 Sep 2023 20:46:21 +0200 Subject: [PATCH 03/16] Initial commit --- src/lib/components/Carousel.svelte | 61 ++++ src/lib/components/index.ts | 1 + src/routes/docs/+page.svelte | 561 ++++++++++++++++++++++++----- 3 files changed, 536 insertions(+), 87 deletions(-) create mode 100644 src/lib/components/Carousel.svelte diff --git a/src/lib/components/Carousel.svelte b/src/lib/components/Carousel.svelte new file mode 100644 index 0000000000..db4074bd9a --- /dev/null +++ b/src/lib/components/Carousel.svelte @@ -0,0 +1,61 @@ + + +
+ +
+ + +
+
+
+ +
+ + diff --git a/src/lib/components/index.ts b/src/lib/components/index.ts index 6d13e00cee..26f0f08b86 100644 --- a/src/lib/components/index.ts +++ b/src/lib/components/index.ts @@ -6,3 +6,4 @@ export { default as Phone } from './Phone.svelte'; export { default as Newsletter } from './Newsletter.svelte'; export { default as Tooltip } from './Tooltip.svelte'; export { default as Article } from './Article.svelte'; +export { default as Carousel } from './Carousel.svelte'; diff --git a/src/routes/docs/+page.svelte b/src/routes/docs/+page.svelte index 222e9b8323..bcdfecb86e 100644 --- a/src/routes/docs/+page.svelte +++ b/src/routes/docs/+page.svelte @@ -1,4 +1,5 @@ @@ -46,11 +49,9 @@ -
- -
+