private async Task <string> RenameFile(Guid id) { FileUpdateModel fileUpdateModel = new FileUpdateModel(); RestClient client = new RestClient(); ActivityIndicatorToggle(false); var newName = await DisplayPromptAsync("Rename", "Enter new name"); if (newName.IndexOf('.') != -1) { return("Please do not include file type in name"); } ActivityIndicatorToggle(true); if (!string.IsNullOrEmpty(newName)) { fileUpdateModel.Name = newName; var responseMessage = client.Put("api/files", id, UserInfo.Token, JsonConvert.SerializeObject(fileUpdateModel)); if (responseMessage.StatusCode == System.Net.HttpStatusCode.NoContent) { return(""); } else { return("There was an error updating file"); } } return(""); }
public async Task <IActionResult> Index(IFormFile formfile) { var randomName = Path.GetRandomFileName().Replace(".", ""); var fileName = System.IO.Path.GetFileName(formfile.FileName); var newFileName = $"{ randomName }{ Path.GetExtension(formfile.FileName)}"; var path = $"upload/{randomName}{Path.GetExtension(formfile.FileName)}"; if (!System.IO.File.Exists(path)) { using (var txtFile = System.IO.File.OpenWrite(path)) { using (var uploadedfile = formfile.OpenReadStream()) { uploadedfile.CopyTo(txtFile); } } } var client = new AmazonS3Client(); var file = new FileInfo(path); var request = new PutObjectRequest { BucketName = "atmahad", FilePath = file.FullName, Key = newFileName }; var response = await client.PutObjectAsync(request); file.Delete(); var model = new FileUpdateModel(); model.AddNewFile(newFileName); // return View(); return(RedirectToAction("Details")); }
public async Task <IActionResult> Add(IFormFile csvFile) { var randomName = Path.GetRandomFileName().Replace(".", ""); var fileName = System.IO.Path.GetFileName(csvFile.FileName); var newFileName = $"{ randomName }{ Path.GetExtension(csvFile.FileName)}"; var path = $"upload/{randomName}{Path.GetExtension(csvFile.FileName)}"; if (!System.IO.File.Exists(path)) { using (var imageFile = System.IO.File.OpenWrite(path)) { using (var uploadedfile = csvFile.OpenReadStream()) { uploadedfile.CopyTo(imageFile); } } } var client = new AmazonS3Client(); var file = new FileInfo(path); var request = new PutObjectRequest { BucketName = "practicenet", FilePath = file.FullName, Key = newFileName }; var response = await client.PutObjectAsync(request); if (response.HttpStatusCode == System.Net.HttpStatusCode.OK) { var model = new FileUpdateModel(); model.AddFiledetails(newFileName); } return(View()); }
/// <summary> /// Creates list of File Record value class from file lines and returns /// </summary> /// <param name="lines"></param> /// <param name="delimeter"></param> /// <param name="stringBuilder"></param> /// <returns></returns> public List <FileUpdateModel> CreateDictionaryListForLoad(string[] lines, string delimeter, ref StringBuilder stringBuilder) { var fileValues = new List <FileUpdateModel>(); for (int i = 0; i < lines.Length; i++) { if (lines[i].Contains(delimeter)) { var index = lines[i].IndexOf(delimeter); var first = lines[i].Substring(0, index); var second = lines[i].Substring(index + delimeter.Length); var fileRecordValue = new FileUpdateModel { UniqueAttrValue = first, UpdateAttrValue = second }; fileValues.Add(fileRecordValue); } else { stringBuilder.AppendLine($"Delimeter not found for the line : Line No : {i + 1}"); } } stringBuilder.AppendLine($"Total records to be processed are : {fileValues.Count}"); return(fileValues); }
public IActionResult Add() { var model = new FileUpdateModel(); return(View(model)); }