public ActionResult Index(MakeAPostViewModel model, IFormFile file) { var user = HttpContext.Session.Get <User>("User"); // user = GetValidUserForNewlyRegistered(user); //Get user with userID for newly registered users var currentWeather = HttpContext.Session.Get <RootObject>("CurrentWeather"); // <---save image to root folder---> // check if file is selected if (file == null || file.Length == 0) { return(Content("File not selected.")); } // get path string imageName = GetUniqueFileName(file.FileName); string currentDirectory = Directory.GetCurrentDirectory(); string path_to_Images = currentDirectory + "\\wwwroot\\UserFiles\\Images\\" + imageName; Console.WriteLine(path_to_Images); //Good up to here Console.WriteLine("File Stream is failing?"); //copy file to target using (var stream = new FileStream(path_to_Images, FileMode.Create)) { // save filename to NewPost.ImageFile Console.WriteLine(path_to_Images); model.NewPost.ImageFile = imageName; file.CopyTo(stream); // <---end save image---> } //Good past here ViewData["FilePath"] = "faker"; //Add Post Console.WriteLine("Make a post right now"); var post = PostHandler.AddPost(user, currentWeather, model.NewPost.ImageFile, model.NewPost.BlogPost).GetAwaiter().GetResult(); if (post != null) { Console.WriteLine("Post went through"); } else { Console.WriteLine("Problem with post"); } //Put to database here return(RedirectToAction("Index", "Landing")); }
private async void DownloadPosts(string path) { bool outOfPost = false; int id = 0; while (!outOfPost) { byte[] output = await FirebaseHelper.DownloadBytes($"{path}{id}.json"); string json = Encoding.ASCII.GetString(output); await postHandler.AddPost(json); if (output == null) { outOfPost = true; } id++; } }
// Start is called before the first frame update async void Start() { // Debug FirebaseHelper.TestingVoid(); // Debug groupInfo = JsonConvert.DeserializeObject <GroupInfo>(PlayerPrefs.GetString("GroupInfo")); GroupName.text = groupInfo.name; List <string> postJsons = new List <string>(); // Download Post FirebaseHelper.DownloadBytes("groups/0000001.json"); // Download Post foreach (string json in postJsons) { await postHandler.AddPost(json); } }