Categories > Firebase > rex_firebase_storage

Introduction

Files storage in firebase.

Links


Categories > Firebase > rex_firebase_storageIntroductionLinksDependenceUsageFileUploadBrief flowComplete flowMultiple files uplodingDownloadAccess control allow originDeleteMetadataSet valueCustom metadataGetUpdateSecurity rules

Dependence

Usage

File

Upload

Brief flow
CallbackYesNoActionis successCondition:On completeCondition:On errorExpression:LastDownloadURLExpression:LastMetadataExpression:LastErrorMessageExpression:LastErrorCodeAction:Upload from data URLAction:Upload from spriteAction:Upload from file chooser
  1. Uploading

  2. Callback

    • Success : Condition:On complete

      • Expression:LastDownloadURL

      • Expression:LastMetadata, returns metadata in JSON string

        • Expression:LastMetadata( key ), returns a key
        • Expression:LastMetadata( key, defaultValue ), retruns defaultValue if key is not existed
    • Failed : Condition:On error

      • Error : Expression:LastErrorMessage, Expression:LastErrorCode (reference)
Complete flow
State:Idle State:Uploading State:PauseStart eventFinished eventsPause eventResume eventIdleUploading+Condition:On upload progressPausedAction:Upload from data URLAction:Upload from spriteAction:Upload from file chooser+Condition:On startingEvent Completed:+Condition:On completedExpression:LastDownloadURLExpression:LastMetadata Event Error:+Condition:On errorExpression:LastErrorMessageExpression:LastErrorCode Action:Cancel+Condition:On canceledAction:Pause+Condition:On pausedAction:Resume+Condition:On resmue
Multiple files uploding

Put or create this rex_firebase_storage object for each file uploading.

Download

CallbackYesNoActionis successCondition:On get download URLCondition:On get download URL errorExpression:LastDownloadURLCondition:File doesn't exist Expression:LastErrorMessageExpression:LastErrorCodeAction:Get download url
Access control allow origin

Follows these steps to allow loading images to sprite from firebase storage.

  1. Install gsutil

  2. Add cors.json file in local (d:\cors.json)

     
    xxxxxxxxxx
    [
      {
        "origin": ["*"],
        "method": ["GET"],
        "maxAgeSeconds": 3600
      }
    ]

    replace * by your domain of application.

  1. Type command

    gsutil cors set d:\cors.json gs://exampleproject.appspot.com

    in command line window. Replace exampleproject.appspot.com by your storageBucket link.

Delete

Reference

CallbackYesNoActionis successCondition:On deletedCondition:On deleted errorExpression:LastErrorMessageExpression:LastErrorCodeAction:Detete
  1. Action:Detete

  2. Callback

    • Success : Condition:On deleted

    • Failed : Condition:On deleted error

      • Error : Expression:LastErrorMessage, Expression:LastErrorCode (reference)

Metadata

Reference

Set value

Sample capx

set metadata before uploading file.

Metadata will be cleaned after uploading.

Custom metadata

Custom metadata is an object containing string->string mappings. For example,

Set `customMetadata.version to 0.1.3.4 will add key version, value 0.1.3.4 in customMetadata.

Get

CallbackYesNoActionis successCondition:On get metadataCondition:On get metadata errorExpression:LastMetadataExpression:LastErrorMessageExpression:LastErrorCodeAction:Get metadata
  1. Action:Get metadata

  2. Callback

    • Success : Condition:On get metadata

      • `Expression:LastMetadata, returns metadata in JSON string

        • Expression:LastMetadata( key ), returns a key
        • Expression:LastMetadata( key, defaultValue ), retruns defaultValue if key is not existed
    • Failed : Condition:On get metadata error

      • Error : Expression:LastErrorMessage, Expression:LastErrorCode (reference)

Update

CallbackYesNoActionis successCondition:On update metadataCondition:On update metadata errorExpression:LastMetadataExpression:LastErrorMessageExpression:LastErrorCodeAction:Update metadata
  1. Action:Update metadata

  2. Callback

    • Success : Condition:On get metadata

      • `Expression:LastMetadata, returns metadata in JSON string

        • Expression:LastMetadata( key ), returns a key
        • Expression:LastMetadata( key, defaultValue ), retruns defaultValue if key is not existed
    • Failed : Condition:On get metadata error

      • Error : Expression:LastErrorMessage, Expression:LastErrorCode (reference)

Security rules

Reference