Beispiel #1
0
        void UploadFile(object args)
        {
            object[]     arr     = (object[])args;
            Stream       stream  = (Stream)arr[0];
            MemoryStream mStream = new MemoryStream();

            byte[] buffer    = new byte[1024];
            int    bytesRead = 0;

            while (true)
            {
                bytesRead = stream.Read(buffer, 0, buffer.Length);
                if (bytesRead == 0)
                {
                    break;
                }
                mStream.Write(buffer, 0, bytesRead);
            }
            string    dir         = (string)arr[1];
            string    fileName    = (string)arr[2];
            string    contentType = (string)arr[3];
            WebUpload upload      = new WebUpload();

            upload.UploadUrl = this.UploadUrl;
            upload.Rename    = false;
            upload.Overwrite = true;
            upload.Files     = new UploadFile[] { new UploadFile(mStream, fileName, contentType) };
            upload.SavePath  = dir;
            upload.Upload();
        }
Beispiel #2
0
        public ActionResult WebUpLoad()
        {
            HttpPostedFileBase uploadFile   = Request.Files["file"];
            string             FilePathName = HttpContext.Server.MapPath("../UpLoad/");
            //string M = "M" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + ".jpg";
            string S = DateTime.Now.ToString("yyyyMMddHHmmssfff") + ".jpg";

            if (uploadFile.ContentLength > 0)
            {
                if (!Directory.Exists(FilePathName))//如果不存在就创建file文件夹
                {
                    Directory.CreateDirectory(FilePathName);
                }
                //获得保存路径
                string filePath = Path.Combine(FilePathName,
                                               Path.GetFileName(S));
                uploadFile.SaveAs(filePath);
                ////压缩图片
                //BasePage.GetPicThumbnail(filePath, FilePathName + "/" + M);
            }
            WebUpload path = new WebUpload();

            path.Path += "/UpLoad/" + S;

            return(Json(new
            {
                path
            }));
        }
Beispiel #3
0
        public WebUploadResult UploadGame(FileInfo fileToUpload, string authKey, int turnId)
        {
            WebUpload cmd = new WebUpload();

            cmd.Execute(new WebUploadParam("Game/UploadSaveClient", fileToUpload, File.ReadAllBytes(fileToUpload.FullName), authKey, turnId));
            return(cmd.Result);
        }
Beispiel #4
0
        /// <summary>
        /// 文件上传统一入口
        /// </summary>
        /// <returns></returns>
        public ContentResult Uploader()
        {
            AjaxResult result = new AjaxResult();

            try
            {
                string             urlPath    = string.Format("~/{0}/", Server.UrlDecode(Request.Params["uploadPath"]));
                HttpPostedFileBase postedfile = Request.Files["filedata"];
                WebUpload          upload     = new WebUpload(postedfile);
                string             filePath   = upload.UploadServer(urlPath);
                string             url        = Url.Content(filePath);
                result.Add("status", "1").Add("message", "上传成功").Add("url", url);
            }
            catch (Exception ex)
            {
                result.IsSuccess = false;
                result.Add("status", "0").Add("message", "上传失败,错误信息:" + ex.Message).Add("url", "");
            }
            return(Content(result.GetJsonString()));
        }