Ejemplo n.º 1
0
        public string Receive()
        {
            bool thumb = Convert.ToBoolean(HttpContext.Current.Request.Headers["Uploader-Thumb"]);

            int thumb_width = Convert.ToInt32(HttpContext.Current.Request.Headers["Uploader-ThumbHeight"]);
            int thumb_height = Convert.ToInt32(HttpContext.Current.Request.Headers["Uploader-ThumbWidth"]);
            string name = HttpContext.Current.Request.Headers["Uploader-Name"];

            TFile file = new TFile(HttpContext.Current.Server.MapPath("~/uploads/images"), HttpContext.Current.Server.MapPath("~/uploads/thumbnails"), thumb_width, thumb_height);

            if (file.UploadAjax(HttpContext.Current.Request.InputStream, name , thumb) == -1) //fail
            {
                return "false";
            }
            else //success
            {
                return "true";
            }
        }
Ejemplo n.º 2
0
        public async Task<ActionResult> Receive()
        {
            bool thumb = true;

            int thumb_width = 200;
            int thumb_height = 200;
            string name = Request.Headers["UploaderName"];

            bool chunk = bool.Parse(Request.Headers["Chunk"]);

            if (chunk)
            {
                var fileName = Request.Headers["FileName"];
                var size = int.Parse(Request.Headers["FileSize"]);
                
                CFile file = null;

                //Check it if there is a file with that name and if there is not create one
                if (!chunkFilesPath.ContainsKey(fileName))
                {
                    file = new CFile(Server.MapPath("~/uploads") + "/" + fileName, size);
                    chunkFilesPath.Add(fileName, file);
                }

                //Write the partion of the file with the position.
                if (chunkFilesPath.TryGetValue(fileName, out file))
                {
                    var stream = Request.InputStream;
                    var position = int.Parse(Request.Headers["ChunkPosition"]);

                    file.Upload(stream, position);
                }

                //If it is %100 then remove it from the dictionary.
                if (file.Percent == 100)
                {
                    chunkFilesPath.Remove(fileName);
                }

                return Json(true);
            }
            else
            {
                TFile file = new TFile(Server.MapPath("~/uploads/images"), Server.MapPath("~/uploads/thumbnails"), thumb_width, thumb_height);

                if (file.UploadAjax(Request.InputStream, name, thumb) == -1) //fail
                {
                    return Json(false);
                }
                else //success
                {
                    return Json(true);
                }

            }

        }