How to share files with Huawei cloud storage service

The recent project decided to integrate the cloud storage service of Huawei AGC to store data files uploaded by users. in the data server.

Downloading on demand can greatly reduce the package body of the application, and using this cloud storage product, you can use the interface provided by the SDK, without paying attention to the operation and maintenance and deployment of the background server, which greatly reduces the development manpower.

At present, we are mainly conducting preliminary research and integration according to specific usage scenarios. Currently, a file sharing scenario is involved. Currently, we are conducting relevant research on the file sharing scenario.

Create a share on the AGC interface

Huawei's AGC cloud storage service provides an AGC console, where you can operate and manage files as an administrator.

Regarding the file sharing managed by AGC, in the official document, the title is to  create a token . This title name may be difficult to understand, but it is actually creating a sharing link. Corresponding document:

https://developer.huawei.com/consumer/cn/doc/development/AppGallery-connect-Guides/agc-cloudstorage-manage-0000001055566160#ZH-CN_TOPIC_0000001158145127__section19261128682

The operation steps are as follows:

1. Log in to the AGC console, click My Projects , and find your cloud storage project. Select Build - Cloud Storage in the left navigation bar .   

2. Select a file and select the details of the action bar 

3. In the pop-up box, you can see the content of the shared token. Each file matches a shared token by default. When a file has a token, that token can be used to download the current file.

cke_7919.png

4. Click Copy to copy the token. The copied token is a download link, through which the file can be downloaded directly.  

Create shares within the app

Huawei AGC cloud storage service also provides SDKs for multiple platforms. You can directly integrate the SDK in Android applications or IOS applications. Through the interface provided by the SDK, you can directly perform file-related operations. Of course, you can also directly create file sharing links. .

The following takes the Android platform as an example to introduce how to integrate the SDK and create a file sharing link.

1. Add the Maven repository address to the project-level build.gradle:

buildscript {
repositories {
maven { url 'https://developer.huawei.com/repo/'}
}

dependencies {
classpath 'com.huawei.agconnect:agcp:1.5.2.300'
}
}
allprojects {
repositories {
maven { url 'https://developer.huawei.com/repo/'}
}
}

2. Add AGCP plugin and agc configuration file

Add the following agcp plugin to the application-level build.gradle

apply plugin: 'com.huawei.agconnect'

In the AGC console, under My Projects - Project Settings, download the agconnect-services.json file and download it to the project's app path

cke_7920.png

3. Add SDK dependencies in application-level build.gradle

dependencies {
implementation 'com.huawei.agconnect:agconnect-storage:1.3.1.200'
}

4. Initialize SDK

Use the getInstance() interface for initialization.

private void initAGCStorageManagement() {
mAGCStorageManagement = AGCStorageManagement.getInstance("Bucket Name");
}

5. Create a reference to the corresponding file and get the download link

private void downloadURL() {
final String path = "test.txt";
StorageReference storageReference = mAGCStorageManagement.getStorageReference(path);
Task<Uri> downloadUrlTask = storageReference.getDownloadUrl();
downloadUrlTask.addOnSuccessListener(new OnSuccessListener<Uri>() {
@Override
public void onSuccess(Uri uri) {
Log.i("getUrl","getURL Success: " + uri.toString());
}
});
}

Get the download link and you can share the file.

Reference link:

  • Huawei AppGallery Connect cloud storage service—console management files:

https://developer.huawei.com/consumer/cn/doc/development/AppGallery-connect-Guides/agc-cloudstorage-manage-0000001055566160

  • Cloud storage service, Android SDK API interface documentation

https://developer.huawei.com/consumer/cn/doc/development/AppGallery-connect-References/storagereference-0000001054767243

{{o.name}}
{{m.name}}

Guess you like

Origin my.oschina.net/u/4478396/blog/5520011