예제 #1
0
        // Email verification [Route("emailVerification")]

        // Social login (dunno if we'll actually use this)


        // ////////////////////////////////////////////////////////
        // Most of this should be moved to the Media services
        // File upload
        //[HttpPost]
        //[Route("upload")]
        public void UploadFile()
        {
            /*This method works and creates a fully-hydrated request model*/
            try
            {
                // get variables first
                NameValueCollection nvc = HttpContext.Current.Request.Form;
                var model   = new UploadRequest();
                var request = HttpContext.Current.Request;
                // iterate through and map user values to strongly typed model
                foreach (string kvp in nvc.AllKeys)
                {
                    PropertyInfo propInfo = model.GetType().GetProperty(kvp, BindingFlags.Public | BindingFlags.Instance);
                    if (propInfo != null)
                    {
                        propInfo.SetValue(model, nvc[kvp], null);
                    }
                }
                // Attach uploaded file itself to the model
                model.File = new HttpPostedFileWrapper(HttpContext.Current.Request.Files["file"]);

                // set filename
                model.FileName = Guid.NewGuid() + model.File.FileName;

                // Save file to project uploads
                string filePath = HttpContext.Current.Server.MapPath("~/App_Data/uploads/" + model.FileName);

                model.File.SaveAs(filePath);

                // Send the file to AWS file storage and capture the resource URL
                //S3Handler s3 = new S3Handler();
                //model.Location = s3.UploadFile(filePath, model.FileName, true);
                // Tie up loose ends on the model
                if (model.FolderName == null)
                {
                    model.FolderName = "No Folder";
                }
                // Save file information in DB
                //UploadService.InsertUpload(model);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }