File storage

Update time: 2024/03/14 18:45:33

The IM SDK for Web utilizes the Netease Object Storage (NOS) service as the default storage solution. However, if your application's user base is dispersed beyond Mainland China, you have the option to select AWS S3 for storage instead.

Converged storage

Converged storage relies on the S3 SDK. To reduce the size of the IM SDK for Web, install the AWS S3 SDK within your application and inject it during the initialization process.

javascriptimport s3 from 'aws-sdk/clients/s3'

nim.getInstance({
  ...,
  providers:{
    s3
  }
})

Send a file

File storage depends on the policies implemented by CommsEase servers and the request parameters used for file transmission. To activate converged storage, configure the "commonUpload" parameter as true. If CommsEase servers prioritize S3 storage in the policy deployment, opt for S3 storage; otherwise, utilize NOS storage.

Receive file messages

If authentication is not required in the configuration, you can utilize the file URL provided in the received file message. However, if authentication is enabled, follow the following method for processing the received file message.

javascriptnim.protocol.getFileAuthToken({
  type: 2,
  done: (data) => console.log(data)
}) 

Get the token and ttl value

Add the token and ttl value to the URL of the file.

javascript`?nim-mixstore-ctoken=nim-mixstore-ctoken=${token}&appKey=${appKey}&uid=${account}`

You can use the URL to access the file.

getFileAuthToken

This method has the following two parameters

shelltype: A value of 2 indicates global token-based authentication with an expiration time. A value of 3 indicates URL-based authentication

urls: If type=3 for URl-based authentication, add an array of URLs.

getFileAuthToken return token and TTL. The TTL is the expiration time of the token in seconds. You can manage tokens based on the TTL.

Was this page helpful?
Yes
No
  • Converged storage
  • Send a file
  • Receive file messages
  • getFileAuthToken