Unity UTF-8 for files' descriptions

0 votes

Please help with UploadFile Services. Unity SDK.

My font is not English base. However, it appears correctly in side Unity and GUI.

After I uploaded on APP42. All of the file's descriptions are broken.

How can I deal with that?

uploadService.UploadFileForUser(fileNameuserNamefilePathfileType"description is not English base"callBack);  

C# please.

thank you much.

 

asked Aug 27, 2014 in App42 Cloud API-BaaS by antm.vn (45 points)

1 Answer

0 votes
 
Best answer

Hello Antm,

Thanks for writing to us.

You can easily deal with non englist character by saving your data in base64 encoding and then decode back after fetching it back. Please find the code snippet below for encoding and decoding your non english character:

String fileName = "<Your_file_name>";
String userName = "Nick";
String description = System.Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes ("许多快乐")); 
String filePath = "Your Local File Path";
String fileType = "<Your_file_type>"; 
App42Log.SetDebug(true);        //Prints output in your editor console
uploadService.UploadFileForUser(fileName, userName, filePath, fileType, description, new UnityCallBack());
public class UnityCallBack : App42CallBack
{
    public void OnSuccess(object response)
    {
        Upload upload = (Upload) response;  
        IList<Upload.File>  fileList = upload.GetFileList();
        for(int i=0; i < fileList.Count; i++)
        {
            App42Log.Console("fileName is " + fileList[i].GetName());
            App42Log.Console("fileType is " + fileList[i].GetType());
            App42Log.Console("fileUrl is " + fileList[i].GetUrl());
            App42Log.Console("TinyUrl Is  : " + fileList[i].GetTinyUrl());
            App42Log.Console("fileDescription is " + System.Text.Encoding.UTF8.GetString (System.Convert.FromBase64String (fileList[i].GetDescription())));
        }
    }
 
    public void OnException(Exception e)
    {
        App42Log.Console("Exception : " + e);
}
}
Let us know if you have more question for us.
Thanks
answered Aug 27, 2014 by hs00105 (2,005 points)
selected Aug 28, 2014 by antm.vn
it works but when I tried to retrieve the string it has error cause if
==
FormatException: Invalid length.
==
I know this is not APP42 error just because of my description is a bit long when decoding. How can I solve that?
just ignore it. Here for who getting same issue

public string EncodeBase64(string data)
        {
            string s = data.Trim().Replace(" ", "+");
            if (s.Length % 4 > 0)
                s = s.PadRight(s.Length + 4 - s.Length % 4, '=');
            return Encoding.UTF8.GetString(Convert.FromBase64String(s));
        }

thanks!
Download Widgets
Welcome to ShepHertz Product line forum, where you can ask questions and receive answers from the community. You can also reach out to us on support@shephertz.com
...