smartfoxserver UploadFile question,help...

Post here all your questions related with SmartFoxServer .Net/Unity3D API

Moderators: Lapo, Bax

niitcolin
Posts: 1
Joined: 18 Mar 2010, 05:26

smartfoxserver UploadFile question,help...

Postby niitcolin » 18 Mar 2010, 05:51

I'm from china,English is not good,Please forgive.

I want use SFS+Unity upload pictures,Encounter a problem.


code follows

Unity Code
using UnityEngine;
using System.IO;
using System;
using System.Collections;

using System.Collections.Generic;
using System.Text.RegularExpressions;

using SmartFoxClientAPI;
using SmartFoxClientAPI.Data;
using SmartFoxClientAPI.Util;

public class FileUpload : MonoBehaviour {

private SmartFoxClient smartFox;
private string serverIP = "127.0.0.1";
private string serverPort = "9339";
public bool debug = true;
private bool connectionAttempt = false;

public GUISkin thisMetalGUISkin;
private Rect rctWindow2;
private bool blnToggleState = false;
private float fltSliderValue = 0.5f;
private float fltScrollerValue = 0.5f;
public string location;

private string[] strs;
private int index;
private string path;

public GUIStyle fileStyle;
public GUIStyle dirStyle;

public string filter;

public Texture2D fileTexture;
public Texture2D dirTexture;
private Vector2 scrollPosition;

void Awake(){
if (SmartFox.IsInitialized() ) {
smartFox = SmartFox.Connection;
} else {
try {
smartFox = new SmartFoxClient(debug);
smartFox.runInQueueMode = true;
} catch ( Exception e ) {
print(e.ToString());
}
}
SFSEvent.onConnection += OnConnection;

rctWindow2 = new Rect(260, 30, 520, 520);
location = Application.dataPath;
strs = new string[20];
index = 0;
path = location;
}


/************
* Callbacks from the SFS API
************/
void OnConnection(bool success, string error) {
if ( success ) {
SmartFox.Connection = smartFox;
} else {
print(error);
}
}


void OnGUI(){
if (!connectionAttempt) {
connectionAttempt = true;
smartFox.Connect(serverIP, Convert.ToInt32(serverPort));
}else if (smartFox.IsConnected()) {
GUI.skin = thisMetalGUISkin;
rctWindow2 = GUI.Window(1, rctWindow2, DoMyWindow2, "FileUpload Panel", GUI.skin.GetStyle("window"));
}
}


void DoMyWindow2(int windowID){
scrollPosition = GUILayout.BeginScrollView (scrollPosition,GUILayout.Width(490),GUILayout.Height(447));
GUILayout.BeginVertical();
FileBrowser( location, 0, 0);
GUILayout.EndVertical();
GUILayout.EndScrollView ();

GUILayout.BeginHorizontal();
GUILayout.TextField(path);
if(GUILayout.Button(" Upload ")){
smartFox.UploadFile(path);
}
GUILayout.EndHorizontal();

GUI.DragWindow();
}


void FileBrowser( string location, int spaceNum, int index)
{
FileInfo fileSelection;
DirectoryInfo directoryInfo;
DirectoryInfo directorySelection;

//
fileSelection = new FileInfo( location );
if( fileSelection.Attributes == FileAttributes.Directory )
directoryInfo = new DirectoryInfo( location );
else
directoryInfo = fileSelection.Directory;

//
GUILayout.BeginVertical();

foreach( DirectoryInfo dirInfo in directoryInfo.GetDirectories()){
GUILayout.BeginHorizontal();
GUILayout.Space(spaceNum);
GUILayout.Label(dirTexture,dirStyle,GUILayout.Width(12));
if( GUILayout.Button(dirInfo.Name, dirStyle)) {
strs[index] = dirInfo.FullName;
path = dirInfo.FullName;
}
GUILayout.EndHorizontal();
if(dirInfo.FullName == strs[index] && strs[index] != location)
FileBrowser(strs[index], spaceNum + 20, index+1);
}

fileSelection = SelectList(directoryInfo.GetFiles(), null, fileStyle, fileTexture, spaceNum) as FileInfo;
if( fileSelection != null )
path = fileSelection.FullName;

GUILayout.EndVertical();
}

private object SelectList( ICollection list, object selected, GUIStyle style, Texture image, int spaceNum)
{
foreach( object item in list )
{
//just show the name of directory and file
FileSystemInfo info = item as FileSystemInfo;
GUILayout.BeginHorizontal();
GUILayout.Space(spaceNum);
GUILayout.Label(image,style,GUILayout.Width(12));
if( GUILayout.Button(info.Name, style)) {
selected = item;
}
GUILayout.EndHorizontal();
}
return selected;
}
}


Error messages

NotSupportedException: http://127.0.0.1:8080/default/upload.py?id=-1&nick=
System.Net.WebRequest.GetCreator (System.String prefix)
System.Net.WebRequest.Create (System.Uri requestUri)
System.Net.WebClient.SetupRequest (System.Uri uri)
System.Net.WebClient.SetupRequest (System.Uri uri, System.String method)
System.Net.WebClient.UploadFileCore (System.Uri address, System.String method, System.String fileName)
System.Net.WebClient.UploadFile (System.Uri address, System.String method, System.String fileName)
System.Net.WebClient.UploadFile (System.String address, System.String method, System.String fileName)
(wrapper remoting-invoke-with-check) System.Net.WebClient:UploadFile (string,string,string)
SmartFoxClientAPI.SmartFoxClient.UploadFile (System.String filePath, Int32 id, System.String nick, Int32 port)
SmartFoxClientAPI.SmartFoxClient.UploadFile (System.String filePath)
FileUpload.DoMyWindow2 (Int32 windowID) (at Assets\Resources\FileUploadScript\FileUpload.cs:95)
UnityEngine.GUI+_Window.Do (UnityEngine.IDList idlist) (at C:\builds\unity-trunk\unity\Runtime\Export\Generated\GUI.cs:1089)
UnityEngine.GUI.BeginWindows (UnityEngine.Event e, Int32 skinMode, UnityEngine.IDList idlist) (at C:\builds\unity-trunk\unity\Runtime\Export\Generated\GUI.cs:1293)

Please help me,Please give me a example..

Return to “.Net / Unity3D API”

Who is online

Users browsing this forum: No registered users and 1 guest