aw-test 0.0.2

Appwrite Rust SDK
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
use crate::client::{Client, ParamType};
use std::collections::HashMap;
use crate::services::AppwriteException;
use crate::models;
use serde_json::json;
use std::io::Read;

#[derive(Clone)]
pub struct Storage {
  client: Client
}

impl Storage {  
    pub fn new(client: &Client) -> Self {
        Self {
            client: client.clone()
        }
    }

    /// Get a list of all the storage buckets. You can use the query params to
    /// filter your results.
    pub fn list_buckets(&self, search: Option<&str>, limit: Option<i64>, offset: Option<i64>, cursor: Option<&str>, cursor_direction: Option<&str>, order_type: Option<&str>) -> Result<models::BucketList, AppwriteException> {
        let path = "/storage/buckets";
        let  headers: HashMap<String, String> = [
            ("content-type".to_string(), "application/json".to_string()),
        ].iter().cloned().collect();

        let search:&str = match search {
            Some(data) => data,
            None => ""
        };

        let cursor:&str = match cursor {
            Some(data) => data,
            None => ""
        };

        let cursor_direction:&str = match cursor_direction {
            Some(data) => data,
            None => ""
        };

        let order_type:&str = match order_type {
            Some(data) => data,
            None => ""
        };

        let  params: HashMap<String, ParamType> = [
            ("search".to_string(), ParamType::String(search.to_string())),
            ("limit".to_string(),  ParamType::OptionalNumber(limit)),
            ("offset".to_string(),  ParamType::OptionalNumber(offset)),
            ("cursor".to_string(), ParamType::String(cursor.to_string())),
            ("cursorDirection".to_string(), ParamType::String(cursor_direction.to_string())),
            ("orderType".to_string(), ParamType::String(order_type.to_string())),
        ].iter().cloned().collect();

        let response = self.client.clone().call("GET", &path, Some(headers), Some(params) );

        let processedResponse:models::BucketList = match response {
            Ok(r) => {
                match r.json() {
                    Ok(json) => json,
                    Err(e) => {
                        return Err(AppwriteException::new(format!("Error parsing response json: {}", e), 0, "".to_string()));
                    }
                }
            }
            Err(e) => {
                return Err(e);
            }
        };

        Ok(processedResponse)
    }

    /// Create a new storage bucket.
    pub fn create_bucket(&self, bucket_id: &str, name: &str, permission: &str, read: Option<&[&str]>, write: Option<&[&str]>, enabled: Option<bool>, maximum_file_size: Option<i64>, allowed_file_extensions: Option<&[&str]>, encryption: Option<bool>, antivirus: Option<bool>) -> Result<models::Bucket, AppwriteException> {
        let path = "/storage/buckets";
        let  headers: HashMap<String, String> = [
            ("content-type".to_string(), "application/json".to_string()),
        ].iter().cloned().collect();

        let read:&[&str] = match read {
            Some(data) => data,
            None => &[]
        };

        let write:&[&str] = match write {
            Some(data) => data,
            None => &[]
        };

        let allowed_file_extensions:&[&str] = match allowed_file_extensions {
            Some(data) => data,
            None => &[]
        };

        let  params: HashMap<String, ParamType> = [
            ("bucketId".to_string(), ParamType::String(bucket_id.to_string())),
            ("name".to_string(), ParamType::String(name.to_string())),
            ("permission".to_string(), ParamType::String(permission.to_string())),
            ("read".to_string(), ParamType::Array(read.into_iter().map(|x| ParamType::String(x.to_string())).collect())),
            ("write".to_string(), ParamType::Array(write.into_iter().map(|x| ParamType::String(x.to_string())).collect())),
            ("enabled".to_string(), ParamType::OptionalBool(enabled)),
            ("maximumFileSize".to_string(),  ParamType::OptionalNumber(maximum_file_size)),
            ("allowedFileExtensions".to_string(), ParamType::Array(allowed_file_extensions.into_iter().map(|x| ParamType::String(x.to_string())).collect())),
            ("encryption".to_string(), ParamType::OptionalBool(encryption)),
            ("antivirus".to_string(), ParamType::OptionalBool(antivirus)),
        ].iter().cloned().collect();

        let response = self.client.clone().call("POST", &path, Some(headers), Some(params) );

        let processedResponse:models::Bucket = match response {
            Ok(r) => {
                match r.json() {
                    Ok(json) => json,
                    Err(e) => {
                        return Err(AppwriteException::new(format!("Error parsing response json: {}", e), 0, "".to_string()));
                    }
                }
            }
            Err(e) => {
                return Err(e);
            }
        };

        Ok(processedResponse)
    }

    /// Get a storage bucket by its unique ID. This endpoint response returns a
    /// JSON object with the storage bucket metadata.
    pub fn get_bucket(&self, bucket_id: &str) -> Result<models::Bucket, AppwriteException> {
        let path = "/storage/buckets/bucketId".replace("bucketId", &bucket_id);
        let  headers: HashMap<String, String> = [
            ("content-type".to_string(), "application/json".to_string()),
        ].iter().cloned().collect();

        let  params: HashMap<String, ParamType> = [
        ].iter().cloned().collect();

        let response = self.client.clone().call("GET", &path, Some(headers), Some(params) );

        let processedResponse:models::Bucket = match response {
            Ok(r) => {
                match r.json() {
                    Ok(json) => json,
                    Err(e) => {
                        return Err(AppwriteException::new(format!("Error parsing response json: {}", e), 0, "".to_string()));
                    }
                }
            }
            Err(e) => {
                return Err(e);
            }
        };

        Ok(processedResponse)
    }

    /// Update a storage bucket by its unique ID.
    pub fn update_bucket(&self, bucket_id: &str, name: &str, permission: &str, read: Option<&[&str]>, write: Option<&[&str]>, enabled: Option<bool>, maximum_file_size: Option<i64>, allowed_file_extensions: Option<&[&str]>, encryption: Option<bool>, antivirus: Option<bool>) -> Result<models::Bucket, AppwriteException> {
        let path = "/storage/buckets/bucketId".replace("bucketId", &bucket_id);
        let  headers: HashMap<String, String> = [
            ("content-type".to_string(), "application/json".to_string()),
        ].iter().cloned().collect();

        let read:&[&str] = match read {
            Some(data) => data,
            None => &[]
        };

        let write:&[&str] = match write {
            Some(data) => data,
            None => &[]
        };

        let allowed_file_extensions:&[&str] = match allowed_file_extensions {
            Some(data) => data,
            None => &[]
        };

        let  params: HashMap<String, ParamType> = [
            ("name".to_string(), ParamType::String(name.to_string())),
            ("permission".to_string(), ParamType::String(permission.to_string())),
            ("read".to_string(), ParamType::Array(read.into_iter().map(|x| ParamType::String(x.to_string())).collect())),
            ("write".to_string(), ParamType::Array(write.into_iter().map(|x| ParamType::String(x.to_string())).collect())),
            ("enabled".to_string(), ParamType::OptionalBool(enabled)),
            ("maximumFileSize".to_string(),  ParamType::OptionalNumber(maximum_file_size)),
            ("allowedFileExtensions".to_string(), ParamType::Array(allowed_file_extensions.into_iter().map(|x| ParamType::String(x.to_string())).collect())),
            ("encryption".to_string(), ParamType::OptionalBool(encryption)),
            ("antivirus".to_string(), ParamType::OptionalBool(antivirus)),
        ].iter().cloned().collect();

        let response = self.client.clone().call("PUT", &path, Some(headers), Some(params) );

        let processedResponse:models::Bucket = match response {
            Ok(r) => {
                match r.json() {
                    Ok(json) => json,
                    Err(e) => {
                        return Err(AppwriteException::new(format!("Error parsing response json: {}", e), 0, "".to_string()));
                    }
                }
            }
            Err(e) => {
                return Err(e);
            }
        };

        Ok(processedResponse)
    }

    /// Delete a storage bucket by its unique ID.
    pub fn delete_bucket(&self, bucket_id: &str) -> Result<serde_json::value::Value, AppwriteException> {
        let path = "/storage/buckets/bucketId".replace("bucketId", &bucket_id);
        let  headers: HashMap<String, String> = [
            ("content-type".to_string(), "application/json".to_string()),
        ].iter().cloned().collect();

        let  params: HashMap<String, ParamType> = [
        ].iter().cloned().collect();

        let response = self.client.clone().call("DELETE", &path, Some(headers), Some(params) );

        match response {
            Ok(r) => {
                let status_code = r.status();
                if status_code == reqwest::StatusCode::NO_CONTENT {
                    Ok(json!(true))
                } else {
                    Ok(serde_json::from_str(&r.text().unwrap()).unwrap())
                }
            }
            Err(e) => {
                Err(e)
            }
        }
    }

    /// Get a list of all the user files. You can use the query params to filter
    /// your results. On admin mode, this endpoint will return a list of all of the
    /// project's files. [Learn more about different API modes](/docs/admin).
    pub fn list_files(&self, bucket_id: &str, search: Option<&str>, limit: Option<i64>, offset: Option<i64>, cursor: Option<&str>, cursor_direction: Option<&str>, order_type: Option<&str>) -> Result<models::FileList, AppwriteException> {
        let path = "/storage/buckets/bucketId/files".replace("bucketId", &bucket_id);
        let  headers: HashMap<String, String> = [
            ("content-type".to_string(), "application/json".to_string()),
        ].iter().cloned().collect();

        let search:&str = match search {
            Some(data) => data,
            None => ""
        };

        let cursor:&str = match cursor {
            Some(data) => data,
            None => ""
        };

        let cursor_direction:&str = match cursor_direction {
            Some(data) => data,
            None => ""
        };

        let order_type:&str = match order_type {
            Some(data) => data,
            None => ""
        };

        let  params: HashMap<String, ParamType> = [
            ("search".to_string(), ParamType::String(search.to_string())),
            ("limit".to_string(),  ParamType::OptionalNumber(limit)),
            ("offset".to_string(),  ParamType::OptionalNumber(offset)),
            ("cursor".to_string(), ParamType::String(cursor.to_string())),
            ("cursorDirection".to_string(), ParamType::String(cursor_direction.to_string())),
            ("orderType".to_string(), ParamType::String(order_type.to_string())),
        ].iter().cloned().collect();

        let response = self.client.clone().call("GET", &path, Some(headers), Some(params) );

        let processedResponse:models::FileList = match response {
            Ok(r) => {
                match r.json() {
                    Ok(json) => json,
                    Err(e) => {
                        return Err(AppwriteException::new(format!("Error parsing response json: {}", e), 0, "".to_string()));
                    }
                }
            }
            Err(e) => {
                return Err(e);
            }
        };

        Ok(processedResponse)
    }

    /// Create a new file. Before using this route, you should create a new bucket
    /// resource using either a [server
    /// integration](/docs/server/database#storageCreateBucket) API or directly
    /// from your Appwrite console.
    /// 
    /// Larger files should be uploaded using multiple requests with the
    /// [content-range](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Range)
    /// header to send a partial request with a maximum supported chunk of `5MB`.
    /// The `content-range` header values should always be in bytes.
    /// 
    /// When the first request is sent, the server will return the **File** object,
    /// and the subsequent part request must include the file's **id** in
    /// `x-appwrite-id` header to allow the server to know that the partial upload
    /// is for the existing file and not for a new one.
    /// 
    /// If you're creating a new file using one of the Appwrite SDKs, all the
    /// chunking logic will be managed by the SDK internally.
    /// 
    pub fn create_file(&self, bucket_id: &str, file_id: &str, file: std::path::PathBuf, read: Option<&[&str]>, write: Option<&[&str]>) -> Result<models::File, AppwriteException> {
        let path = "/storage/buckets/bucketId/files".replace("bucketId", &bucket_id);
        let mut headers: HashMap<String, String> = [
            ("content-type".to_string(), "multipart/form-data".to_string()),
        ].iter().cloned().collect();

        let read:&[&str] = match read {
            Some(data) => data,
            None => &[]
        };

        let write:&[&str] = match write {
            Some(data) => data,
            None => &[]
        };

        let mut params: HashMap<String, ParamType> = [
            ("fileId".to_string(), ParamType::String(file_id.to_string())),
            ("read".to_string(), ParamType::Array(read.into_iter().map(|x| ParamType::String(x.to_string())).collect())),
            ("write".to_string(), ParamType::Array(write.into_iter().map(|x| ParamType::String(x.to_string())).collect())),
        ].iter().cloned().collect();

        let mut fileBuf = std::fs::File::open(file.clone()).unwrap();

        let size = fileBuf.metadata().unwrap().len();

        match size {
            size if size <= crate::client::CHUNK_SIZE => {
                params.insert("file".to_string(), ParamType::FilePath(file));
                match self.client.clone().call("POST", &path, Some(headers), Some(params)) {
                    Ok(r) => {
                        Ok(r.json::<models::File>().unwrap())
                    }
                    Err(e) => {
                        Err(e)
                    }
                }
            }
            _ => {
                // Stream Data.
                let mut id = "".to_string();

                let mut resumeCounter: u64 = 0;
                let totalCounters = (((size / crate::client::CHUNK_SIZE) as f64).ceil() as u64) + 1;

                if file_id != "unique()" {
                    let filePath = format!("/storage/buckets/bucketId/files{}", file_id);
                    match self.client.clone().call("GET", &filePath, Some(headers.clone()), None) {
                        Ok(r) => {
                            match r.json::<serde_json::Value>() {
                                Ok(data) => {
                                    resumeCounter = data["chunksUploaded"].as_u64().unwrap();
                                },
                                Err(_e) => ()
                            };
                        }
                        Err(_e) => ()
                    };
                }

                let response: reqwest::blocking::Response;

                for counter in resumeCounter..totalCounters {
                    let mut headers: HashMap<String, String> = [
                        ("content-type".to_string(), "multipart/form-data".to_string()),
                    ].iter().cloned().collect();

                    let mut params = params.clone();

                    headers.insert("content-range".to_string(), format!("bytes {}-{}/{}", (counter * crate::client::CHUNK_SIZE),
                        std::cmp::min((counter * crate::client::CHUNK_SIZE) + crate::client::CHUNK_SIZE - 1, size), size));

                    if id.len() != 0 {
                        headers.insert("x-appwrite-id".to_string(), id.to_string());
                    }

                    let mut chunk = Vec::with_capacity(crate::client::CHUNK_SIZE as usize);

                    match fileBuf.by_ref().take(crate::client::CHUNK_SIZE).read_to_end(&mut chunk) {
                        Ok(_) => (),
                        Err(e) => {
                            return Err(AppwriteException::new(format!("A error occoured. ERR: {}, This could either be a connection error or an internal Appwrite error. Please check your Appwrite instance logs. ", e), 0, "".to_string()))
                        }
                    };

                    params.insert("file".to_string(), ParamType::StreamData(chunk, file.file_name().unwrap().to_string_lossy().to_string()));

                    let response = match self.client.clone().call("POST", &path, Some(headers), Some(params)) {
                        Ok(r) => r,
                        Err(e) => {
                            return Err(e);
                        }
                    };

                    // If last chunk, return the response.
                    if counter == totalCounters - 1 {
                        return Ok(response.json::<models::File>().unwrap());
                    } else {
                        if id.len() == 0 {
                            id = response.json::<serde_json::Value>().unwrap()["$id"].as_str().unwrap().to_owned();
                        }
                    }
                };

                return Err(AppwriteException::new("Error uploading chunk data.".to_string(), 500, "0".to_string()));
            }
        }
    }

    /// Get a file by its unique ID. This endpoint response returns a JSON object
    /// with the file metadata.
    pub fn get_file(&self, bucket_id: &str, file_id: &str) -> Result<models::File, AppwriteException> {
        let path = "/storage/buckets/bucketId/files/fileId".replace("bucketId", &bucket_id).replace("fileId", &file_id);
        let  headers: HashMap<String, String> = [
            ("content-type".to_string(), "application/json".to_string()),
        ].iter().cloned().collect();

        let  params: HashMap<String, ParamType> = [
        ].iter().cloned().collect();

        let response = self.client.clone().call("GET", &path, Some(headers), Some(params) );

        let processedResponse:models::File = match response {
            Ok(r) => {
                match r.json() {
                    Ok(json) => json,
                    Err(e) => {
                        return Err(AppwriteException::new(format!("Error parsing response json: {}", e), 0, "".to_string()));
                    }
                }
            }
            Err(e) => {
                return Err(e);
            }
        };

        Ok(processedResponse)
    }

    /// Update a file by its unique ID. Only users with write permissions have
    /// access to update this resource.
    pub fn update_file(&self, bucket_id: &str, file_id: &str, read: Option<&[&str]>, write: Option<&[&str]>) -> Result<models::File, AppwriteException> {
        let path = "/storage/buckets/bucketId/files/fileId".replace("bucketId", &bucket_id).replace("fileId", &file_id);
        let  headers: HashMap<String, String> = [
            ("content-type".to_string(), "application/json".to_string()),
        ].iter().cloned().collect();

        let read:&[&str] = match read {
            Some(data) => data,
            None => &[]
        };

        let write:&[&str] = match write {
            Some(data) => data,
            None => &[]
        };

        let  params: HashMap<String, ParamType> = [
            ("read".to_string(), ParamType::Array(read.into_iter().map(|x| ParamType::String(x.to_string())).collect())),
            ("write".to_string(), ParamType::Array(write.into_iter().map(|x| ParamType::String(x.to_string())).collect())),
        ].iter().cloned().collect();

        let response = self.client.clone().call("PUT", &path, Some(headers), Some(params) );

        let processedResponse:models::File = match response {
            Ok(r) => {
                match r.json() {
                    Ok(json) => json,
                    Err(e) => {
                        return Err(AppwriteException::new(format!("Error parsing response json: {}", e), 0, "".to_string()));
                    }
                }
            }
            Err(e) => {
                return Err(e);
            }
        };

        Ok(processedResponse)
    }

    /// Delete a file by its unique ID. Only users with write permissions have
    /// access to delete this resource.
    pub fn delete_file(&self, bucket_id: &str, file_id: &str) -> Result<serde_json::value::Value, AppwriteException> {
        let path = "/storage/buckets/bucketId/files/fileId".replace("bucketId", &bucket_id).replace("fileId", &file_id);
        let  headers: HashMap<String, String> = [
            ("content-type".to_string(), "application/json".to_string()),
        ].iter().cloned().collect();

        let  params: HashMap<String, ParamType> = [
        ].iter().cloned().collect();

        let response = self.client.clone().call("DELETE", &path, Some(headers), Some(params) );

        match response {
            Ok(r) => {
                let status_code = r.status();
                if status_code == reqwest::StatusCode::NO_CONTENT {
                    Ok(json!(true))
                } else {
                    Ok(serde_json::from_str(&r.text().unwrap()).unwrap())
                }
            }
            Err(e) => {
                Err(e)
            }
        }
    }

    /// Get a file content by its unique ID. The endpoint response return with a
    /// 'Content-Disposition: attachment' header that tells the browser to start
    /// downloading the file to user downloads directory.
    pub fn get_file_download(&self, bucket_id: &str, file_id: &str) -> Result<Vec<u8>, AppwriteException> {
        let path = "/storage/buckets/bucketId/files/fileId/download".replace("bucketId", &bucket_id).replace("fileId", &file_id);
        let  headers: HashMap<String, String> = [
            ("content-type".to_string(), "application/json".to_string()),
        ].iter().cloned().collect();

        let  params: HashMap<String, ParamType> = [
        ].iter().cloned().collect();

        let response = self.client.clone().call("GET", &path, Some(headers), Some(params) );

        let processedResponse:Vec<u8> = match response {
            Ok(mut r) => {
                let mut buf: Vec<u8> = vec![];
                match r.copy_to(&mut buf) {
                    Ok(_) => (),
                    Err(e) => {
                        return Err(AppwriteException::new(format!("Error copying response to buffer: {}", e), 0, "".to_string()));
                    }
                };
                buf
            }
            Err(e) => {
                return Err(e);
            }
        };

        Ok(processedResponse)
    }

    /// Get a file preview image. Currently, this method supports preview for image
    /// files (jpg, png, and gif), other supported formats, like pdf, docs, slides,
    /// and spreadsheets, will return the file icon image. You can also pass query
    /// string arguments for cutting and resizing your preview image. Preview is
    /// supported only for image files smaller than 10MB.
    pub fn get_file_preview(&self, bucket_id: &str, file_id: &str, width: Option<i64>, height: Option<i64>, gravity: Option<&str>, quality: Option<i64>, border_width: Option<i64>, border_color: Option<&str>, border_radius: Option<i64>, opacity: Option<f64>, rotation: Option<i64>, background: Option<&str>, output: Option<&str>) -> Result<Vec<u8>, AppwriteException> {
        let path = "/storage/buckets/bucketId/files/fileId/preview".replace("bucketId", &bucket_id).replace("fileId", &file_id);
        let  headers: HashMap<String, String> = [
            ("content-type".to_string(), "application/json".to_string()),
        ].iter().cloned().collect();

        let gravity:&str = match gravity {
            Some(data) => data,
            None => ""
        };

        let border_color:&str = match border_color {
            Some(data) => data,
            None => ""
        };

        let background:&str = match background {
            Some(data) => data,
            None => ""
        };

        let output:&str = match output {
            Some(data) => data,
            None => ""
        };

        let  params: HashMap<String, ParamType> = [
            ("width".to_string(),  ParamType::OptionalNumber(width)),
            ("height".to_string(),  ParamType::OptionalNumber(height)),
            ("gravity".to_string(), ParamType::String(gravity.to_string())),
            ("quality".to_string(),  ParamType::OptionalNumber(quality)),
            ("borderWidth".to_string(),  ParamType::OptionalNumber(border_width)),
            ("borderColor".to_string(), ParamType::String(border_color.to_string())),
            ("borderRadius".to_string(),  ParamType::OptionalNumber(border_radius)),
            ("opacity".to_string(),  ParamType::OptionalFloat(opacity)),
            ("rotation".to_string(),  ParamType::OptionalNumber(rotation)),
            ("background".to_string(), ParamType::String(background.to_string())),
            ("output".to_string(), ParamType::String(output.to_string())),
        ].iter().cloned().collect();

        let response = self.client.clone().call("GET", &path, Some(headers), Some(params) );

        let processedResponse:Vec<u8> = match response {
            Ok(mut r) => {
                let mut buf: Vec<u8> = vec![];
                match r.copy_to(&mut buf) {
                    Ok(_) => (),
                    Err(e) => {
                        return Err(AppwriteException::new(format!("Error copying response to buffer: {}", e), 0, "".to_string()));
                    }
                };
                buf
            }
            Err(e) => {
                return Err(e);
            }
        };

        Ok(processedResponse)
    }

    /// Get a file content by its unique ID. This endpoint is similar to the
    /// download method but returns with no  'Content-Disposition: attachment'
    /// header.
    pub fn get_file_view(&self, bucket_id: &str, file_id: &str) -> Result<Vec<u8>, AppwriteException> {
        let path = "/storage/buckets/bucketId/files/fileId/view".replace("bucketId", &bucket_id).replace("fileId", &file_id);
        let  headers: HashMap<String, String> = [
            ("content-type".to_string(), "application/json".to_string()),
        ].iter().cloned().collect();

        let  params: HashMap<String, ParamType> = [
        ].iter().cloned().collect();

        let response = self.client.clone().call("GET", &path, Some(headers), Some(params) );

        let processedResponse:Vec<u8> = match response {
            Ok(mut r) => {
                let mut buf: Vec<u8> = vec![];
                match r.copy_to(&mut buf) {
                    Ok(_) => (),
                    Err(e) => {
                        return Err(AppwriteException::new(format!("Error copying response to buffer: {}", e), 0, "".to_string()));
                    }
                };
                buf
            }
            Err(e) => {
                return Err(e);
            }
        };

        Ok(processedResponse)
    }

    pub fn get_usage(&self, range: Option<&str>) -> Result<models::UsageStorage, AppwriteException> {
        let path = "/storage/usage";
        let  headers: HashMap<String, String> = [
            ("content-type".to_string(), "application/json".to_string()),
        ].iter().cloned().collect();

        let range:&str = match range {
            Some(data) => data,
            None => ""
        };

        let  params: HashMap<String, ParamType> = [
            ("range".to_string(), ParamType::String(range.to_string())),
        ].iter().cloned().collect();

        let response = self.client.clone().call("GET", &path, Some(headers), Some(params) );

        let processedResponse:models::UsageStorage = match response {
            Ok(r) => {
                match r.json() {
                    Ok(json) => json,
                    Err(e) => {
                        return Err(AppwriteException::new(format!("Error parsing response json: {}", e), 0, "".to_string()));
                    }
                }
            }
            Err(e) => {
                return Err(e);
            }
        };

        Ok(processedResponse)
    }

    pub fn get_bucket_usage(&self, bucket_id: &str, range: Option<&str>) -> Result<models::UsageBuckets, AppwriteException> {
        let path = "/storage/bucketId/usage".replace("bucketId", &bucket_id);
        let  headers: HashMap<String, String> = [
            ("content-type".to_string(), "application/json".to_string()),
        ].iter().cloned().collect();

        let range:&str = match range {
            Some(data) => data,
            None => ""
        };

        let  params: HashMap<String, ParamType> = [
            ("range".to_string(), ParamType::String(range.to_string())),
        ].iter().cloned().collect();

        let response = self.client.clone().call("GET", &path, Some(headers), Some(params) );

        let processedResponse:models::UsageBuckets = match response {
            Ok(r) => {
                match r.json() {
                    Ok(json) => json,
                    Err(e) => {
                        return Err(AppwriteException::new(format!("Error parsing response json: {}", e), 0, "".to_string()));
                    }
                }
            }
            Err(e) => {
                return Err(e);
            }
        };

        Ok(processedResponse)
    }
}