示例#1
0
 public ActionResult <string> UploadFile(string id, string type)
 {
     try
     {
         if (type != "profil")
         {
             throw new Exception("File type not supported for this URL");
         }
         var file = Request.Form.Files[0];
         var ext  = file.FileName.Split('.').Last();
         var entrepriseCollection = new EntrepriseCollection();
         var entreprise           = entrepriseCollection.GetItems(e => e.Id == id).FirstOrDefault();
         if (entreprise == null)
         {
             throw new Exception("Entreprise not found");
         }
         StorageAzureManager storage = new StorageAzureManager("profilsentreprises");
         var path = storage.UpladFile($"entreprises/{id}.{ext}", file.OpenReadStream(), file.ContentType).GetAwaiter().GetResult();
         entreprise.EmployeurIdentite.ImageProfil = path;
         entrepriseCollection.UpdateItem(id, entreprise);
         //var stream = new Stream(file)
         return(Ok(path));
     }
     catch (Exception e)
     {
         return(StatusCode(500, e.Message));
     }
 }
示例#2
0
        public ActionResult <string> UploadFile(string fileType, IFormFile file)
        {
            StorageAzureManager storage = new StorageAzureManager(fileType);
            var path = storage.UpladFile(file.FileName, file.OpenReadStream(), file.ContentType).GetAwaiter().GetResult();

            return(path);
        }