Class: Appwrite::Storage
- Defined in:
- lib/appwrite/services/storage.rb
Instance Method Summary collapse
-
#create_bucket(bucket_id:, name:, permissions: nil, file_security: nil, enabled: nil, maximum_file_size: nil, allowed_file_extensions: nil, compression: nil, encryption: nil, antivirus: nil, transformations: nil, description: nil, strip_metadata: nil) ⇒ Bucket
Create a new storage bucket.
-
#create_file(bucket_id:, file_id:, file:, permissions: nil, folder: nil, on_progress: nil) ⇒ File
Create a new file.
-
#delete_bucket(bucket_id:) ⇒ Object
Delete a storage bucket by its unique ID.
-
#delete_file(bucket_id:, file_id:) ⇒ Object
Delete a file by its unique ID.
-
#get_bucket(bucket_id:) ⇒ Bucket
Get a storage bucket by its unique ID.
-
#get_file(bucket_id:, file_id:) ⇒ File
Get a file by its unique ID.
-
#get_file_download(bucket_id:, file_id:, token: nil) ⇒ Object
Get a file content by its unique ID.
-
#get_file_preview(bucket_id:, file_id:, width: nil, height: nil, gravity: nil, quality: nil, border_width: nil, border_color: nil, border_radius: nil, opacity: nil, rotation: nil, background: nil, output: nil, token: nil) ⇒ Object
Get a file preview image.
-
#get_file_view(bucket_id:, file_id:, token: nil) ⇒ Object
Get a file content by its unique ID.
-
#initialize(client) ⇒ Storage
constructor
A new instance of Storage.
-
#list_buckets(queries: nil, search: nil, total: nil) ⇒ BucketList
Get a list of all the storage buckets.
-
#list_files(bucket_id:, queries: nil, search: nil, total: nil) ⇒ FileList
Get a list of all the user files.
-
#update_bucket(bucket_id:, name:, permissions: nil, file_security: nil, enabled: nil, maximum_file_size: nil, allowed_file_extensions: nil, compression: nil, encryption: nil, antivirus: nil, transformations: nil, description: nil, strip_metadata: nil) ⇒ Bucket
Update a storage bucket by its unique ID.
-
#update_file(bucket_id:, file_id:, name: nil, permissions: nil) ⇒ File
Update a file by its unique ID.
Constructor Details
#initialize(client) ⇒ Storage
Returns a new instance of Storage.
5 6 7 |
# File 'lib/appwrite/services/storage.rb', line 5 def initialize(client) @client = client end |
Instance Method Details
#create_bucket(bucket_id:, name:, permissions: nil, file_security: nil, enabled: nil, maximum_file_size: nil, allowed_file_extensions: nil, compression: nil, encryption: nil, antivirus: nil, transformations: nil, description: nil, strip_metadata: nil) ⇒ Bucket
Create a new storage bucket.
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 |
# File 'lib/appwrite/services/storage.rb', line 61 def create_bucket( bucket_id:, name:, permissions: nil, file_security: nil, enabled: nil, maximum_file_size: nil, allowed_file_extensions: nil, compression: nil, encryption: nil, antivirus: nil, transformations: nil, description: nil, strip_metadata: nil ) if bucket_id.nil? raise Appwrite::Exception.new('Missing required parameter: "bucketId"') end if name.nil? raise Appwrite::Exception.new('Missing required parameter: "name"') end api_path = '/storage/buckets' api_params = { bucketId: bucket_id, name: name, permissions: , fileSecurity: file_security, enabled: enabled, maximumFileSize: maximum_file_size, allowedFileExtensions: allowed_file_extensions, compression: compression, encryption: encryption, antivirus: antivirus, transformations: transformations, description: description, stripMetadata: , } api_headers = { "X-Appwrite-Project": @client.get_config('project'), "content-type": 'application/json', "accept": 'application/json', } @client.call( method: 'POST', path: api_path, headers: api_headers, params: api_params, response_type: Models::Bucket ) end |
#create_file(bucket_id:, file_id:, file:, permissions: nil, folder: nil, on_progress: nil) ⇒ File
Create a new file. Before using this route, you should create a new bucket resource using either a server integration API or directly from your Appwrite console.
Larger files should be uploaded using multiple requests with the
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.
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 |
# File 'lib/appwrite/services/storage.rb', line 321 def create_file( bucket_id:, file_id:, file:, permissions: nil, folder: nil, on_progress: nil ) if bucket_id.nil? || bucket_id == '' raise Appwrite::Exception.new('Missing required parameter: "bucketId"') end if file_id.nil? raise Appwrite::Exception.new('Missing required parameter: "fileId"') end if file.nil? raise Appwrite::Exception.new('Missing required parameter: "file"') end api_path = '/storage/buckets/{bucketId}/files' .gsub('{bucketId}', @client.encode_path(bucket_id)) api_params = { fileId: file_id, file: file, permissions: , folder: folder, } api_headers = { "X-Appwrite-Project": @client.get_config('project'), "content-type": 'multipart/form-data', "accept": 'application/json', } id_param_name = "fileId" param_name = 'file' @client.chunked_upload( path: api_path, headers: api_headers, params: api_params, param_name: param_name, id_param_name: id_param_name, on_progress: on_progress, method: 'POST', response_type: Models::File ) end |
#delete_bucket(bucket_id:) ⇒ Object
Delete a storage bucket by its unique ID.
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 |
# File 'lib/appwrite/services/storage.rb', line 227 def delete_bucket( bucket_id: ) if bucket_id.nil? || bucket_id == '' raise Appwrite::Exception.new('Missing required parameter: "bucketId"') end api_path = '/storage/buckets/{bucketId}' .gsub('{bucketId}', @client.encode_path(bucket_id)) api_params = {} api_headers = { "X-Appwrite-Project": @client.get_config('project'), "content-type": 'application/json', "accept": 'application/json', } @client.call( method: 'DELETE', path: api_path, headers: api_headers, params: api_params, ) end |
#delete_file(bucket_id:, file_id:) ⇒ Object
Delete a file by its unique ID. Only users with write permissions have access to delete this resource.
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 |
# File 'lib/appwrite/services/storage.rb', line 465 def delete_file( bucket_id:, file_id: ) if bucket_id.nil? || bucket_id == '' raise Appwrite::Exception.new('Missing required parameter: "bucketId"') end if file_id.nil? || file_id == '' raise Appwrite::Exception.new('Missing required parameter: "fileId"') end api_path = '/storage/buckets/{bucketId}/files/{fileId}' .gsub('{bucketId}', @client.encode_path(bucket_id)) .gsub('{fileId}', @client.encode_path(file_id)) api_params = {} api_headers = { "X-Appwrite-Project": @client.get_config('project'), "content-type": 'application/json', "accept": 'application/json', } @client.call( method: 'DELETE', path: api_path, headers: api_headers, params: api_params, ) end |
#get_bucket(bucket_id:) ⇒ Bucket
Get a storage bucket by its unique ID. This endpoint response returns a JSON object with the storage bucket metadata.
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 |
# File 'lib/appwrite/services/storage.rb', line 123 def get_bucket( bucket_id: ) if bucket_id.nil? || bucket_id == '' raise Appwrite::Exception.new('Missing required parameter: "bucketId"') end api_path = '/storage/buckets/{bucketId}' .gsub('{bucketId}', @client.encode_path(bucket_id)) api_params = {} api_headers = { "X-Appwrite-Project": @client.get_config('project'), "accept": 'application/json', } @client.call( method: 'GET', path: api_path, headers: api_headers, params: api_params, response_type: Models::Bucket ) end |
#get_file(bucket_id:, file_id:) ⇒ File
Get a file by its unique ID. This endpoint response returns a JSON object with the file metadata.
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 |
# File 'lib/appwrite/services/storage.rb', line 379 def get_file( bucket_id:, file_id: ) if bucket_id.nil? || bucket_id == '' raise Appwrite::Exception.new('Missing required parameter: "bucketId"') end if file_id.nil? || file_id == '' raise Appwrite::Exception.new('Missing required parameter: "fileId"') end api_path = '/storage/buckets/{bucketId}/files/{fileId}' .gsub('{bucketId}', @client.encode_path(bucket_id)) .gsub('{fileId}', @client.encode_path(file_id)) api_params = {} api_headers = { "X-Appwrite-Project": @client.get_config('project'), "accept": 'application/json', } @client.call( method: 'GET', path: api_path, headers: api_headers, params: api_params, response_type: Models::File ) end |
#get_file_download(bucket_id:, file_id:, token: nil) ⇒ Object
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.
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 |
# File 'lib/appwrite/services/storage.rb', line 506 def get_file_download( bucket_id:, file_id:, token: nil ) if bucket_id.nil? || bucket_id == '' raise Appwrite::Exception.new('Missing required parameter: "bucketId"') end if file_id.nil? || file_id == '' raise Appwrite::Exception.new('Missing required parameter: "fileId"') end api_path = '/storage/buckets/{bucketId}/files/{fileId}/download' .gsub('{bucketId}', @client.encode_path(bucket_id)) .gsub('{fileId}', @client.encode_path(file_id)) api_params = { token: token, } api_headers = { "X-Appwrite-Project": @client.get_config('project'), "accept": '*/*', } @client.call( method: 'GET', path: api_path, headers: api_headers, params: api_params, ) end |
#get_file_preview(bucket_id:, file_id:, width: nil, height: nil, gravity: nil, quality: nil, border_width: nil, border_color: nil, border_radius: nil, opacity: nil, rotation: nil, background: nil, output: nil, token: nil) ⇒ Object
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. Set output
to auto to receive avif or webp when the client's Accept header
supports it, falling back to the original image format. Preview is
supported only for image files smaller than 10MB.
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 |
# File 'lib/appwrite/services/storage.rb', line 565 def get_file_preview( bucket_id:, file_id:, width: nil, height: nil, gravity: nil, quality: nil, border_width: nil, border_color: nil, border_radius: nil, opacity: nil, rotation: nil, background: nil, output: nil, token: nil ) if bucket_id.nil? || bucket_id == '' raise Appwrite::Exception.new('Missing required parameter: "bucketId"') end if file_id.nil? || file_id == '' raise Appwrite::Exception.new('Missing required parameter: "fileId"') end api_path = '/storage/buckets/{bucketId}/files/{fileId}/preview' .gsub('{bucketId}', @client.encode_path(bucket_id)) .gsub('{fileId}', @client.encode_path(file_id)) api_params = { width: width, height: height, gravity: gravity, quality: quality, borderWidth: border_width, borderColor: border_color, borderRadius: border_radius, opacity: opacity, rotation: rotation, background: background, output: output, token: token, } api_headers = { "X-Appwrite-Project": @client.get_config('project'), "accept": 'image/*', } @client.call( method: 'GET', path: api_path, headers: api_headers, params: api_params, ) end |
#get_file_view(bucket_id:, file_id:, token: nil) ⇒ Object
Get a file content by its unique ID. This endpoint is similar to the download method but returns with no 'Content-Disposition: attachment' header.
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 |
# File 'lib/appwrite/services/storage.rb', line 630 def get_file_view( bucket_id:, file_id:, token: nil ) if bucket_id.nil? || bucket_id == '' raise Appwrite::Exception.new('Missing required parameter: "bucketId"') end if file_id.nil? || file_id == '' raise Appwrite::Exception.new('Missing required parameter: "fileId"') end api_path = '/storage/buckets/{bucketId}/files/{fileId}/view' .gsub('{bucketId}', @client.encode_path(bucket_id)) .gsub('{fileId}', @client.encode_path(file_id)) api_params = { token: token, } api_headers = { "X-Appwrite-Project": @client.get_config('project'), "accept": '*/*', } @client.call( method: 'GET', path: api_path, headers: api_headers, params: api_params, ) end |
#list_buckets(queries: nil, search: nil, total: nil) ⇒ BucketList
Get a list of all the storage buckets. You can use the query params to filter your results.
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 |
# File 'lib/appwrite/services/storage.rb', line 17 def list_buckets( queries: nil, search: nil, total: nil ) api_path = '/storage/buckets' api_params = { queries: queries, search: search, total: total, } api_headers = { "X-Appwrite-Project": @client.get_config('project'), "accept": 'application/json', } @client.call( method: 'GET', path: api_path, headers: api_headers, params: api_params, response_type: Models::BucketList ) end |
#list_files(bucket_id:, queries: nil, search: nil, total: nil) ⇒ FileList
Get a list of all the user files. You can use the query params to filter your results.
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 |
# File 'lib/appwrite/services/storage.rb', line 262 def list_files( bucket_id:, queries: nil, search: nil, total: nil ) if bucket_id.nil? || bucket_id == '' raise Appwrite::Exception.new('Missing required parameter: "bucketId"') end api_path = '/storage/buckets/{bucketId}/files' .gsub('{bucketId}', @client.encode_path(bucket_id)) api_params = { queries: queries, search: search, total: total, } api_headers = { "X-Appwrite-Project": @client.get_config('project'), "accept": 'application/json', } @client.call( method: 'GET', path: api_path, headers: api_headers, params: api_params, response_type: Models::FileList ) end |
#update_bucket(bucket_id:, name:, permissions: nil, file_security: nil, enabled: nil, maximum_file_size: nil, allowed_file_extensions: nil, compression: nil, encryption: nil, antivirus: nil, transformations: nil, description: nil, strip_metadata: nil) ⇒ Bucket
Update a storage bucket by its unique ID.
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 |
# File 'lib/appwrite/services/storage.rb', line 166 def update_bucket( bucket_id:, name:, permissions: nil, file_security: nil, enabled: nil, maximum_file_size: nil, allowed_file_extensions: nil, compression: nil, encryption: nil, antivirus: nil, transformations: nil, description: nil, strip_metadata: nil ) if bucket_id.nil? || bucket_id == '' raise Appwrite::Exception.new('Missing required parameter: "bucketId"') end if name.nil? raise Appwrite::Exception.new('Missing required parameter: "name"') end api_path = '/storage/buckets/{bucketId}' .gsub('{bucketId}', @client.encode_path(bucket_id)) api_params = { name: name, permissions: , fileSecurity: file_security, enabled: enabled, maximumFileSize: maximum_file_size, allowedFileExtensions: allowed_file_extensions, compression: compression, encryption: encryption, antivirus: antivirus, transformations: transformations, description: description, stripMetadata: , } api_headers = { "X-Appwrite-Project": @client.get_config('project'), "content-type": 'application/json', "accept": 'application/json', } @client.call( method: 'PUT', path: api_path, headers: api_headers, params: api_params, response_type: Models::Bucket ) end |
#update_file(bucket_id:, file_id:, name: nil, permissions: nil) ⇒ File
Update a file by its unique ID. Only users with write permissions have access to update this resource.
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 |
# File 'lib/appwrite/services/storage.rb', line 420 def update_file( bucket_id:, file_id:, name: nil, permissions: nil ) if bucket_id.nil? || bucket_id == '' raise Appwrite::Exception.new('Missing required parameter: "bucketId"') end if file_id.nil? || file_id == '' raise Appwrite::Exception.new('Missing required parameter: "fileId"') end api_path = '/storage/buckets/{bucketId}/files/{fileId}' .gsub('{bucketId}', @client.encode_path(bucket_id)) .gsub('{fileId}', @client.encode_path(file_id)) api_params = { name: name, permissions: , } api_headers = { "X-Appwrite-Project": @client.get_config('project'), "content-type": 'application/json', "accept": 'application/json', } @client.call( method: 'PUT', path: api_path, headers: api_headers, params: api_params, response_type: Models::File ) end |