Unity3D 上传日志
来源:互联网 发布:0--100水仙花数java 编辑:程序博客网 时间:2024/05/21 06:41
上传日志到服务器,需要先将日志进行压缩,首先下载压缩库Ionic.Zip.dll
http://yunpan.cn/cj7U6E4RrRh6m 访问密码 b6df
丢到工程的Assets\Plugins目录下
然后
using Ionic.Zip;
接着就可以使用啦
上传文件需要用到WWW,所以要使用协程,所以要继承MonoBehaviour,或者继承MonoBehaviour的子类
public class UploadFile:MonoBehaviour
{
protected override void Start()
{
string filePath="h:/test/test.text";
string savePath="h:/test/test.zip";
#if !UNITY_EDITOR
filePath = "mnt/sdcard/output_log.txt";
savePath = "mnt/sdcard/output_log.zip";
#endif
try
{
if(File.Exists(filePath))
{
using(ZipFile zip = new ZipFile())
{
ZipEntry e = zip.AddFile(filePath,"");
zip.Save(savePath);
}
using(FileStream fs = File.OpenRead(savePath))
{
long i=0;
long length = fs.Length;
byte[] data = new byte[length];
long offset = data.Length>1024?1024:data.Length;
while(i<length)
{
int realRead = fs.Read(data,(int)i,(int)offset);
i+=realRead;
long tem=length -i;
offset=tem>offset?offset:tem;
//以时间为文件名//
DateTime now = DateTime.Now;
string fileName=string.Format("{0}.dat",now.Year+""+now.Month+""+now.Day+"_"+now.Hour+""+now.Minute+""+now.Second);
StartCoroutine(upload(fileName,data));
}
}
}
}
}
IEnumerator upload(string fileName,byte[] data)
{
WWWForm form = new WWWForm();
form.AddField("type","file");
form.AddBinaryData("log_file",data,fileName);
string url="http://192.168.0.119:8080/uploadLog";
#if !UNITY_EDITOR
url = "http://192.168.218.1:8080/uploadLog"; //外网的地址//
#endif
WWW w=new WWW(url,form);
yield return w;
if(w.error != null)
{
Debug.LogError(w.error);
}
else
{
if(w.text != null)
{
Debug.Log("Finished Uploading:"+w.text);
}
}
yield return null;
}
}
- Unity3D 上传日志
- 上传日志
- unity3d版本更新日志
- unity3d编程日志
- 关于Unity3D中的日志
- unity3d崩溃日志存储位置
- Unity3D学习日志第一天
- Unity3D学习日志第二天
- Pomelo+unity3d采坑日志
- Unity3D 07-日志、文本打印
- unity3d 上传本地PC图片
- Unity3D中的svn上传目录
- android-ftp-上传日志
- sftp 上传日志
- 日志实时监控+上传
- 【Android-Unity3D学习日志】Android-Unity3D开发环境搭建
- unity3d使用Log4.net进行日志记录
- Unity3d游戏之游戏日志打印
- the Sieve of Eratosthenes
- 分享到微信/空间/微博
- 测试看看
- 一、我们应当怎样做需求分析
- What is JNI?
- Unity3D 上传日志
- .net经典解读(事件和委托)
- 通过vagrant打造php虚拟机通用环境
- pmap
- Android线程间通信--Handler
- NSSet
- MyBatis Annotation配置
- 二、我们应当怎样做需求调研:初识
- C# List多字段排序