Search Unity

Problem Uploading to Mysql - Longtext field empty

Discussion in 'Scripting' started by Ludopathic, Jan 4, 2017.

  1. Ludopathic

    Ludopathic

    Joined:
    Dec 21, 2016
    Posts:
    12
    Hi guys, I'm using UniFileBrowser to set filepaths and LoginPro to upload the files to the server, I have a script which is working just fine - without errors - and the debug log seems to check out - it loads a png, converts it to a base64 string and then uploads it. However when I check the database, the field where the string is supposed to be saved is empty... Anyone have any ideas?

    Code (CSharp):
    1. public class FileOpen : MonoBehaviour
    2. {
    3.  
    4.    
    5.     public UITexture ProfilePic;
    6.     public static Texture2D tex = null;
    7.     public static String selectedFilePath;
    8.  
    9.     void openFile()
    10.     {
    11.  
    12.  
    13.        UniFileBrowser.use.OpenFileWindow(OpenFile);
    14.         Debug.Log("opening filebrowser");
    15.  
    16.     }
    17.  
    18.     public static Texture2D LoadPNG(string selectedFilePath)
    19.     {
    20.      
    21.         byte[] fileData;
    22.      
    23.             fileData = File.ReadAllBytes(selectedFilePath);
    24.         Debug.Log(fileData);
    25.             tex = new Texture2D(2, 2);
    26.             tex.LoadImage(fileData); //..this will auto-resize the texture dimensions.
    27.      
    28.         return tex;
    29.                }
    30.  
    31.  
    32.  
    33.   //OPENS THE FILE AND SENDS IT TO THE SERVER
    34.     void OpenFile(string filePath)
    35.     {
    36.         selectedFilePath = filePath;
    37.         Debug.Log("Showing selected filepath" + filePath);
    38.                 LoadPNG(selectedFilePath);
    39.  
    40.  
    41.                 byte[] bytes = tex.EncodeToPNG();
    42.                 Debug.Log("Encoding to png and setting to string" +bytes);
    43.                 string fileToSend = Convert.ToBase64String(bytes);
    44.                 Debug.Log("Converting to Base64 and setting to string" +fileToSend);
    45.                 string[] datas = new string[1];
    46.                     datas[0] = fileToSend;
    47.                 Debug.Log("This should be the string tha gets uploaded" +datas[0]);
    48.                     LoginPro.Manager.ExecuteOnServer("SaveFile", SendToServer_Success, SendToServer_Error, datas);
    49.  
    50.        
    51.  
    52.  
    53.     }
     
  2. Not_Sure

    Not_Sure

    Joined:
    Dec 13, 2011
    Posts:
    3,546
    I'm not too up to speed on what you're doing, but could the problem be that you're trying to save it in test mode when project needs to be built to save to a directory?

    There's a few functions that won't work with preprocessor (in test mode) and I think file I/O is one of them.
     
  3. Ludopathic

    Ludopathic

    Joined:
    Dec 21, 2016
    Posts:
    12
    I fixed it, the PHP script I was running was expecting array data of [3] (to protect against SQL injection) and was rejecting the string. I added the array indices to the code and it works now.
     
  4. Not_Sure

    Not_Sure

    Joined:
    Dec 13, 2011
    Posts:
    3,546
    Well that's good.

    Sorry I couldn't be more help.