Web 部署
Web服务器安装WebDAV发布和管理服务
服务器安装WebDeploy
https://www.iis.net/downloads/microsoft/web-deploy
IIS管理器权限添加用户
网站——部署——启用WebDeploy发布
开放相关端口,如8172
Web服务器安装WebDAV发布和管理服务
服务器安装WebDeploy
https://www.iis.net/downloads/microsoft/web-deploy
IIS管理器权限添加用户
网站——部署——启用WebDeploy发布
开放相关端口,如8172
using System;
using System.IO;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.Internal;
using Microsoft.AspNetCore.Mvc;
namespace WebApplication1.Controllers
{
[Route("api/[controller]")]
[ApiController]
public class UpLoadController : ControllerBase
{
private readonly IHostingEnvironment _hostingEnvironment;
public UpLoadController(IHostingEnvironment hostingEnvironment)
{
_hostingEnvironment = hostingEnvironment;
}
[HttpPost]
public string Post([FromForm] IFormCollection formCollection)
{
string result = "";
string webRootPath = _hostingEnvironment.ContentRootPath;
string contentRootPath = _hostingEnvironment.ContentRootPath;
FormFileCollection filelist = (FormFileCollection)formCollection.Files;
foreach (IFormFile file in filelist)
{
String Tpath = "/" + DateTime.Now.ToString("yyyy-MM-dd") + "/";
string name = file.FileName;
string FileName = DateTime.Now.ToString("yyyyMMddHHmmssfff");
string FilePath = webRootPath + Tpath;
string type = Path.GetExtension(name);
DirectoryInfo di = new DirectoryInfo(FilePath);
if (!di.Exists)
{
di.Create();
}
using (FileStream fs = System.IO.File.Create(FilePath + FileName + type))
{
// 复制文件
file.CopyTo(fs);
// 清空缓冲区数据
fs.Flush();
}
result = "1";
}
return result;
}
}
}
Unity中调用
private IEnumerator UpLoadImg(string filePath)
{
byte[] bs = File.ReadAllBytes(filePath);
Log.Debug("bs.Length:" + bs.Length.ToString());
WWWForm test = new WWWForm();
test.AddBinaryData("imgbase.jpg", bs, "imgbase.jpg");
WWW www = new WWW("http://192.168.2.185/api/upload", test);
yield return www;
Log.Debug(www.text);
}
以Win7兼容模式运行
sudo nano /usr/share/applications/Unity.desktop
[Desktop Entry]
Encoding=UTF-8
Name=Unity
Comment=Unity
Exec=/opt/Unity-2017.4.10f1/Editor/Unity
Icon=/opt/Unity-2017.4.10f1/Editor/Data/Resources/LargeUnityIcon.png
Terminal=false
StartupNotify=true
Type=Application
Categories=Application;Development;