Guides & References

Before You Start

Adding the Configuration File

AppGallery Connect provides a configuration file that stores app configurations to simplify the configuration procedure. You must add the configuration file to your project and integrate the AppGallery Connect plugin. The plugin can automatically load your app information in AppGallery Connect to your development environment.

  1. Verify the default_storage setting under service > cloudstorage in the agconnect-services.json file.

    Example:
    "cloudstorage":{
         "default_storage":"Default storage instance name",
             "storage_url":"https://agc-storage-drcn.platform.dbankcloud.cn"
         }

    If default_storage is not set, the Cloud Storage SDK will fail to be initialized. In this case, set this attribute to the storage instance name on the Build > Cloud Storage page.

  2. Please download your latest config file from AGC and import it into the Assets/StreamingAssets folder. (It will change after you enable cloud storage)

Modifying the AndroidManifest File

To read and write files and access the Internet, configure the following permissions in the AndroidManifest.xml file:

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

If your app is integrated with the SDK for Android (API level 29 or higher), also add the following attributes to the application in AndroidManifest.xml to gain permission to access external files:

    <application
          android:name=".App"
          android:allowBackup="false"
          android:requestLegacyExternalStorage="true"

Security Rules

examples:

// Security rule declaration
agc.cloud.storage[
   // Match a specific file under the images directory.
   match: /{bucket}/images/image.jpg{
      allow read, write:  if true;
   }
// Match any file under the images directory.
   match: /{bucket}/images/{image} {
      allow read, write:  if true;
   }
]
// Allow all
agc.cloud.storage[
   match: /{bucket}/{path=**} {
      allow read, write:  if true;
   }
]
// Reject all
agc.cloud.storage[
   match: /{bucket}/{path=**} {
      allow read, write:  if false;
   }
]
agc.cloud.storage[
    match: /{bucket}/images/{image}{
        allow get:  if true;
        allow list:  if false;
        allow create:  if true;
        allow update:  if true;
        allow delete:  if false;
    }
]
agc.cloud.storage[
    match: /{bucket}/{path=**} {
        allow read, write:  if request.resource.contentType == 'image/jpeg';
    }
]
// Allow all authenticated users
agc.cloud.storage[
    match: /{bucket}/{path=**} {
        allow read, write:  if request.auth != null;
    }
]
// Exclusive to certain users
agc.cloud.storage[
    match: /{bucket}/{userId}/{path=**} {
        allow read, write:  if request.auth.uid == userId;
    }
]

Attributes

The request and resource objects can help security rules obtain more request contexts for more proper control.

The following table lists all attributes in the request object.

AttributeTypeDescription

request.auth.uid

String

Unique ID obtained by a user after the user passes the authentication.

request.path

String

Storage path of the requested resource.

request.time

String

Server time of the request.

request.resource

Mapping <string, string>

Information about a new file resource, which is the same as the resource object information and exists only when the write request is executed.

The following table lists all attributes in the resource object.

AttributeTypeDescription

resource.name

String

Resource file name.

resource.bucket

String

Storage instance name of a resource file.

resource.contentType

String

Resource file type.

resource.contentDisposition

String

Method of disposing of a resource file.

resource.contentEncoding

String

Method of encoding a resource file.

resource.contentLanguage

String

Resource file language.

resource.size

String

Resource file size.

resource.metadata

Mapping <string, string>

User-defined metadata of a resource file, which is in a map structure in the format of <key, value>.

Last updated