Esempio n. 1
0
        //[EpcAuth]
        public async Task <ActionResult> Upload(string only_qiniu)
        {
            return(await RunActionAsync(async() =>
            {
                if ((this.X.context.Request.Files?.Count ?? 0) <= 0)
                {
                    return GetJsonRes("请选择要上传的文件");
                }
                var file = this.X.context.Request.Files[0] ?? throw new ArgumentNullException("文件不存在");
                if (file.ContentLength > Com.MbToB(1))
                {
                    return GetJsonRes("文件过大");
                }

                var qiniu = new QiniuHelper();

                if ((only_qiniu ?? "false").ToBool())
                {
                    var url = qiniu.Upload(file.GetBytes(), Com.GetUUID());
                    return GetJson(new _()
                    {
                        success = true, data = url
                    });
                }
                else
                {
                    var path = Server.MapPath("~/static/upload/");

                    var uploader = new FileUpload()
                    {
                        MaxSize = Com.MbToB(1)
                    };

                    var res = uploader.UploadSingleFile(file, path);
                    if (!res.SuccessUpload)
                    {
                        return GetJsonRes("上传失败");
                    }
                    var url = qiniu.Upload(res.FilePath, Com.GetUUID());

                    await Task.FromResult(1);
                    return GetJson(new _()
                    {
                        success = true, data = url
                    });
                }
            }));
        }
Esempio n. 2
0
        public ActionResult FileUploadAction()
        {
            return(RunActionWhenLogin((loginuser) =>
            {
                string SavePath = Server.MapPath("~/static/upload/link_images/");

                var uploader = new FileUpload()
                {
                    AllowFileType = new string[] { ".gif", ".png", ".jpg", ".jpeg", ".bmp" },
                };
                var file = this.X.context.Request.Files["file"];
                if (file != null)
                {
                    var model = uploader.UploadSingleFile(file, SavePath);
                    var path = model.FilePath;
                    if (model.SuccessUpload && System.IO.File.Exists(path))
                    {
                        try
                        {
                            var url = QiniuHelper.Upload(path, Com.GetUUID());

                            ViewData["img_url"] = url;
                            //删除本地
                            System.IO.File.Delete(path);
                        }
                        catch (Exception e)
                        {
                            e.SaveLog(this.GetType());
                            ViewData["info"] = "上传到七牛错误";
                        }
                    }
                    else
                    {
                        ViewData["info"] = model.Info;
                    }
                }
                return View();
            }));
        }
Esempio n. 3
0
        public string UploadFileAfterCheckRepeat(FileInfo file, string uid,
                                                 ref string file_url, ref string file_name, bool DeleteFileAfterUploadToQiniu = true)
        {
            try
            {
                if (!file.Exists)
                {
                    throw new Exception("无法在磁盘上找到文件");
                }

                var dal = new UpFileDal();

                var dbmodel = new UpFileModel();
                dbmodel.UserID     = uid;
                dbmodel.FileName   = file.Name;
                dbmodel.FileExt    = file.Extension;
                dbmodel.FileSize   = (int)file.Length;
                dbmodel.FilePath   = file.FullName;
                dbmodel.CreateTime = DateTime.Now;
                //获取文件md5值
                dbmodel.FileMD5 = SecureHelper.GetFileMD5(dbmodel.FilePath);
                if (!ValidateHelper.IsPlumpString(dbmodel.FileMD5))
                {
                    throw new Exception("获取文件MD5失败");
                }
                //判断文件是否存在于七牛
                var  qiniu_file        = QiniuHelper.FindEntry(dbmodel.FileMD5);
                bool FindInQiniu       = qiniu_file.HasFile();
                bool uploadToQiniuByMe = false;
                if (FindInQiniu)
                {
                    //直接拿七牛中的文件地址
                    dbmodel.FileUrl = QiniuHelper.GetUrl(dbmodel.FileMD5);
                }
                else
                {
                    var url = QiniuHelper.Upload(file.FullName, dbmodel.FileMD5);
                    dbmodel.FileUrl = url;
                    //标记文件是我上传到七牛的
                    uploadToQiniuByMe = true;
                }
                //运行到这里,七牛已经有文件了
                //判断是否要添加到数据库
                var res = AddFile(dbmodel);
                if (ValidateHelper.IsPlumpString(res))
                {
                    //如果是我上传到七牛的并且保存本地数据库失败就删除
                    if (uploadToQiniuByMe)
                    {
                        QiniuHelper.Delete(dbmodel.FileMD5);
                    }
                    return("保存到数据库失败");
                }

                file_name = dbmodel.FileName;
                file_url  = dbmodel.FileUrl;

                return(SUCCESS);
            }
            catch (Exception e)
            {
                throw e;
            }
            finally
            {
                if (DeleteFileAfterUploadToQiniu)
                {
                    file.Delete();
                }
            }
        }
Esempio n. 4
0
        public IHttpActionResult getMapData(string callback = "")
        {
            var root    = System.Web.HttpContext.Current.Server.MapPath("~/");
            var version = db.systemInfos.Find("dataVer");

            if (version == null)
            {
                return(Json(-1, "找不到版本配置信息"));
            }
            if (!File.Exists(root + "map_" + version.value + ".json"))
            {
                AssetManage.LoadDatabase(version.value);
                var map = new MapData();
                //map.eventQuests = AssetManage.Database.mstEventQuest;
                map.events      = AssetManage.Database.mstEvent;
                map.questGroups = AssetManage.Database.mstQuestGroup;
                //map.messions = AssetManage.Database.mstMission;
                map.svtGroups = AssetManage.Database.mstSvtGroup;
                map.wars      = new List <War>();
                Mapper.Initialize((config) =>
                {
                    config.CreateMap <mstWar, War>();
                    config.CreateMap <mstQuest, Quest>();
                    config.CreateMap <mstSpot, Spot>();
                    config.CreateMap <mstSpotRoad, SpotRoad>();
                });
                AutoMapper.Mapper.Map(AssetManage.Database.mstWar, map.wars);
                foreach (var war in map.wars)
                {
                    war.spots = new List <Spot>();
                    foreach (var spot in AssetManage.Database.mstSpot)
                    {
                        if (spot.warId == war.id)
                        {
                            var nspot = Mapper.Map <mstSpot, Spot>(spot);
                            war.spots.Add(nspot);
                            nspot.quests = new List <Quest>();
                            foreach (var quest in AssetManage.Database.mstQuest)
                            {
                                if (quest.spotId == spot.id)
                                {
                                    var nquest = Mapper.Map <mstQuest, Quest>(quest);
                                    nspot.quests.Add(nquest);
                                    nquest.phases   = new List <mstQuestPhase>();
                                    nquest.releases = new List <mstQuestRelease>();
                                    foreach (var phase in AssetManage.Database.mstQuestPhase)
                                    {
                                        if (phase.questId == quest.id)
                                        {
                                            nquest.phases.Add(phase);
                                        }
                                    }
                                    foreach (var release in AssetManage.Database.mstQuestRelease)
                                    {
                                        if (release.questId == quest.id)
                                        {
                                            nquest.releases.Add(release);
                                        }
                                    }
                                }
                            }
                        }
                    }
                    war.spotRoads = new List <SpotRoad>();
                    foreach (var spotRoad in AssetManage.Database.mstSpotRoad)
                    {
                        if (spotRoad.warId == war.id)
                        {
                            war.spotRoads.Add(Mapper.Map <mstSpotRoad, SpotRoad>(spotRoad));
                        }
                    }
                }
                File.WriteAllText(root + "map_" + version.value + ".json", JsonConvert.SerializeObject(map));
                QiniuHelper.Upload("map_" + version.value + ".json", root + "map_" + version.value + ".json");
            }
            var url = "http://oj3vd47gp.bkt.clouddn.com/map_" + version.value + ".json";

            return(Redirect(url));
        }