public async Task <ActionResult> PostAsync([FromForm] IFormFile file, [FromForm] string access)
        {
            try
            {
                UserService userService = new UserService();
                UserModel   user        = await userService.GetCurrentUserAsync(Request.Cookies["jwt"]);

                AzureStoarge azureStoarge = new AzureStoarge();
                string       blobUrl      = await azureStoarge.UploadAsync(file.OpenReadStream(), file.FileName);

                TagImages search = new TagImages(blobUrl);
                string    tags   = await search.MostCommonTags(20);

                Database database = new Database("images");
                await database.PostImageToDbAsync(file.FileName, blobUrl, user.username, access, tags);

                return(Ok("uploaded"));
            }
            catch (Exception)
            {
                return(NotFound());
            }
        }
示例#2
0
        public async Task <string> Search([FromForm] IFormFile file, [FromForm] string access = "Search")
        {
            IList <ImageModel> results = new List <ImageModel>();

            try
            {
                AzureStoarge azureStoarge = new AzureStoarge();
                string       blobUrl      = await azureStoarge.UploadAsync(file.OpenReadStream(), file.FileName);

                TagImages search = new TagImages(blobUrl);
                string    tags   = await search.MostCommonTags(20);

                Database database = new Database("images");
                //await database.PostImageToDbAsync(file.FileName, blobUrl, "jawadjawid", access, tags);

                results = await database.GetImagesFromDbAsync(access : "public", tags : tags);

                return(JsonConvert.SerializeObject(results));
            }
            catch (Exception)
            {
                return(JsonConvert.SerializeObject(results));
            }
        }
 public SearchController(GalleryDatabaseConnector database, AzureStoarge azureStoarge)
 {
     this.database     = database;
     this.azureStoarge = azureStoarge;
 }
 public UploadController(UserService userService, AzureStoarge azureStoarge, GalleryDatabaseConnector database)
 {
     this.userService  = userService;
     this.azureStoarge = azureStoarge;
     this.database     = database;
 }