Newer
Older
lacoche
committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Threading.Tasks;
using System.Net ;
using System.IO ;
public class WorldAnalysisARFoundationHelper
{
/// <summary>
/// Downaload file http
/// </summary>
/// <param name="toLoad">load url</param>
/// <returns>key and value with local path and file name with extension</returns>
public static async Task<KeyValuePair<string, string> > DownloadFileHTTP(string toLoad)
{
string filePath = "";
string fileName = "";
#if UNITY_EDITOR
string folder = Application.streamingAssetsPath;
#else
string folder = Application.persistentDataPath;
#endif
using (var client = new WebClient())
{
await client.DownloadFileTaskAsync(toLoad, folder + "/Temp.data");
string header_contentDisposition = client.ResponseHeaders["content-disposition"];
if (header_contentDisposition == null)
{
string[] splittedLink = toLoad.Split('/');
fileName = splittedLink[splittedLink.Length - 1];
}
else
{
fileName = new System.Net.Mime.ContentDisposition(header_contentDisposition).FileName;
}
filePath = folder + "/" + fileName;
if (File.Exists(filePath))
{
File.Delete(filePath);
}
File.Move(folder + "/Temp.data", filePath);
}
return new KeyValuePair<string, string>(filePath , fileName);
}
}