NOS Cloud Storage Service

Update time: 2021/09/25 14:34:28

SDK provides a remote file storage service, which enables users to upload and download files via the interface provided by SDK.

Configure File Tag Information

When a file is uploaded to NOS server, file tag and expiration time can be designated, and expiration time is 1d at least. The interface is invoked to configure tag information after SK initialization or before file uploading.

  • API prototype
csharp/// <summary>
/// Developers initialize life cycle of each scene resource used when uploading resources. They can customize 10 scenes at most,
/// and designate life cycle of designated scene resource, and cover (re-designate life cycle) the default scene ("nim_default_im"、"nim_default_profile_icon").
/// </summary>
public static void InitNosTags(System.Collections.Generic.List<NosTagInfo> tags)

Download

Download File via URL

  • API prototype
csharp/// <summary>
/// Download resources
/// </summary>
/// <param name="nosUrl">URL of downloaded resource</param>
/// <param name="resHandler">Callback for download result</param>
/// <param name="prgHandler">Callback for download progress</param>
/// <param name="userData">user data input in the callback for download progress</param>
public static void Download(string nosUrl, DownloadResultHandler resHandler, ProgressResultHandler prgHandler, object userData = null)
  • Example
csharpNIM.Nos.NosAPI.Download("NOSURL", OnDownloadCompleted, DwonloadProgressCallback);

private void OnDownloadCompleted(int rescode, string filePath, string callId, string resId)
{
    if(rescode == 200)
    {
        //File downloaded. filePath is the path for saving the file.
    }
    else
    {
        //File download failed
    }
}

private void DwonloadProgressCallback(ProgressData prgData)
{
    //Callback for download progress
    //prgData.CurrentSize:Size of current downloaded file
    //prgData.TotalSize: Total file size
}

Download File in A Message

  • API prototype
csharp/// <summary>
/// Get resources
/// </summary>
/// <param name="msg">Message body, e.g. NIMVideoMessage NIMAudioMessage NIMFileMessage with the attribute msg_attach will send a message for downloading information</param>
/// <param name="resHandler">Callback for download result</param>
/// <param name="prgHandler">Callback for download progress</param>
public static void DownloadMedia(NIMIMMessage msg, DownloadResultHandler resHandler, ProgressResultHandler prgHandler, object userData = null)
  • Example
csharpNosAPI.DownloadMedia (msg, (rescode, filePath, callId, resId)=>
        {

            UnityEngin.Debug.Log(string.Format("rescode:{0},filepath:{1},callId:{2},resId:{3}",rescode,filePath,callId, resId));
        },
        (prgData)=>
        {
            UnityEngin.Debug.Log(string.Format("curr:{0},total:{1},{2}",prgData.CurrentSize,prgData.TotalSize,prgData.FilePath));
        });

Upload

  • API prototype
csharp/// <summary>
/// Upload resources
/// </summary>
/// <param name="localFile">Complete path of local file</param>
/// <param name="resHandler">Callback for upload result</param>
/// <param name="prgHandler">Callback for upload progress</param>
public static void Upload(string localFile, UploadResultHandler resHandler, ProgressResultHandler prgHandler, object userData = null)
  • Example
csharpNIM.Nos.NosAPI.Upload("FILE PATH", FileUploadCallback, ProgressCallback);
private void FileUploadCallback(int rescode, string url)
{
    if (rescode == 200)
    {
        //Uploaded. Url is the download URL for the file saved in NOS.
    }
    else
    {
        //Upload failed
    }
}

private void ProgressCallback(ProgressData prgData)
{
    //Callback for upload progress
    //prgData.CurrentSize:Size of current uploaded file
    //prgData.TotalSize: Total file size
}

Use Designated Tag for Uploading

The tag shall be configured via InitNosTags. A file cannot be uploaded with uninitialized tag.

  • API prototype
csharp/// <summary>
/// Upload resources
/// </summary>
/// <param name="localFile">Complete path of local file</param>
/// <param name="tag">Scene tag. It is mainly used for determine the time for saving a file.</param>
/// <param name="resHandler">Callback for upload result</param>
/// <param name="prgHandler">Callback for upload progress</param>
public static void Upload2(string localFile, string tag, UploadResultHandler resHandler, ProgressResultHandler prgHandler, object userData = null)

Register Default Download Callback

When receiving a file message, SDK will automatically download the file, and register the download callback to get download progress and result. If automatic download fails, users can manually invoke the download interface and try to download again.

  • API prototype
csharp/// <summary>
//Register download callback, get notification for http download result by registering the callback, and refresh resources
/// </summary>
/// <param name="handler">Callback for download result</param>
/// 
public static void RegDownloadCb(DownloadResultHandler handler)

Register Default Upload Callback

If a message that contains one or more files is sent, the SDK automatically uploads the files. If the file is uploaded successfully, SDK will send download URL of the file to receiver, and register the upload callback to get related upload information.

  • API prototype
csharp/// <summary>
/// (Global callback) Register the upload callback, and then get the notification of HTTP upload result (all notifications for processing function that cannot be configured in the list of parameters triggering HTTP upload task will be sent in this way, for example, send file, image, and audio message, etc.)
/// </summary>
/// <param name="callback"></param>
/// <param name="data"></param>
public static void RegisterDefaultUploadCallback(UploadCb callback, IntPtr data)
Was this page helpful?
Yes
No
  • Configure File Tag Information
  • Download
  • Download File via URL
  • Download File in A Message
  • Upload
  • Use Designated Tag for Uploading
  • Register Default Download Callback
  • Register Default Upload Callback