NOS storage

Update time: 2024/03/07 11:13:59

NIM SDK allows you to set the scene for data stored using the Netease Object Storage (NOS) service. The "scene" represents the type of IM data stored in NOS. By default, the data includes multimedia attachment resources, user profiles, and group information, and the storage of these two types of IM data in NOS does not expire by default. You can specify the expiration time of IM data on NOS. After expiration, the data will be deleted by NOS.

For multimedia attachments, use the default setting: "store attachments in NOS without setting an expiration time".

Prerequisites

Implementation

Preset storage scene

When initializing the SDK, you can set the scene using the nosSceneConfig in the NIMSDKOptions class for multimedia attachments stored on NOS.

The storage scene is defined by NimNosSceneKeyConstant, the main parameters are as follows:

Parameter Description
NIM_DEFAULT_IM Upload the attachment resources of image, audio, video, and file messages sent in P2P chats, group chats, and chat rooms to NOS for storage. The storage will never expire (NEVER_EXPIRE) by default, and the storage expiration time can also be set using updateDefaultIMSceneExpireTime (see the sample code below),
NIM_DEFAULT_PROFILE Upload user profiles and group information (such as avatars) to NOS for storage. The storage will never expire (NEVER_EXPIRE) by default, and the storage expiration time can also be set using updateDefaultProfileSceneExpireTime (see the sample code below)
dart
static SDKOptions getSDKOptions(Context context) {
        SDKOptions options = new SDKOptions();
         // Other options
        options.mNosTokenSceneConfig = createNosTokenScene();
        return options;
}

public static final String TEST_NOS_SCENE_KEY="test_nos_scene_key";

private static NosTokenSceneConfig createNosTokenScene() {
      NosTokenSceneConfig nosTokenSceneConfig = new NosTokenSceneConfig();

      //Update the expiration time for the default scenario (NimNosSceneKeyConstant.NIM_DEFAULT_IM)
      nosTokenSceneConfig.updateDefaultIMSceneExpireTime(1);

      //Update the expiration time for the default scenario (NimNosSceneKeyConstant.NIM_DEFAULT_PROFILE)
      nosTokenSceneConfig.updateDefaultProfileSceneExpireTime(2);

      //Set the custom scene and the corresponding expiration time (days). A value of 0 indicates the storage never expire.
      // Make the sceneKey a constant, which is more convenient to use. Currently, up to 10 custom scenes are supported.
      nosTokenSceneConfig.appendCustomScene(TEST_NOS_SCENE_KEY, 4);
      return nosTokenSceneConfig;
}

Set the storage scene

When creatinga multimedia message, the storage scene of the multimedia resource on the NOS can be set using the nosTokenSceneKey parameter, and the default value is NimNosSceneKeyConstant#NIM_DEFAULT_IM. The multimedia resource sent by a P2P chat, group chat, or chat room is uploaded to the NOS for storage, and the default storage never expires.

Message type
Method Reference
Image message createImageMessage Multimedia messaging
Audio message createAudioMesssage
Video message createVideoMessage
File message createFileMessage

Error codes

Code Description
5 A scene does not exist. resource upload failure.
4 The file was downloaded after it expired, the download failed.
Was this page helpful?
Yes
No
  • Prerequisites
  • Implementation
  • Preset storage scene
  • Set the storage scene
  • Error codes