- Home /
Question by
Ludopathic · Jan 05, 2017 at 06:44 AM ·
unity 5serializationbytearrayimage loader
Using UniFileBrowser and LoginPro to upload file = zero bytes uploaded?
Hi guys, I'm trying to allow the user to select an image file and upload it to my server - am using UniFileBrowser for the selection and trying to serialise the file into bytes that are sent as base64 string to the database via loginPro's system.
The script executes without errors but when I check MYSQL nothing shows up?
public class FileOpen : MonoBehaviour
{
public UITexture ProfilePic;
public static Texture2D tex = null;
public static String selectedFilePath;
void openFile()
{
UniFileBrowser.use.OpenFileWindow(OpenFile);
}
public static Texture2D LoadPNG(string selectedFilePath)
{
byte[] fileData;
fileData = File.ReadAllBytes(selectedFilePath);
tex = new Texture2D(2, 2);
tex.LoadImage(fileData); //..this will auto-resize the texture dimensions.
return tex;
}
//OPENS THE FILE AND SENDS IT TO THE SERVER
void OpenFile(string filePath)
{
selectedFilePath = filePath;
LoadPNG(selectedFilePath);
Texture2D uploadFile = tex;
byte[] bytes = uploadFile.EncodeToPNG();
string fileToSend = Convert.ToBase64String(bytes);
string[] datas = new string[1];
datas[0] = fileToSend;
LoginPro.Manager.ExecuteOnServer("SaveFile", SendToServer_Success, SendToServer_Error, datas);
Comment