Exemplo n.º 1
0
        public IActionResult UploadAvatar()
        {
            string code         = "000000";
            var    returnUpload = new ReturnUpload();

            try
            {
                IFormFileCollection Files = Request.Form.Files;
                if (Files == null || Files.Count == 0)
                {
                    code = "100051";
                }
                else
                {
                    string uploadStr = _uploadFileService.UploadImg(Files[0], _uploadSettings.path, _uploadSettings.avatar, HttpContext.GetIp(), GetJwtIEntity().UserId);
                    returnUpload = JSONHelper.Dseriallize <ReturnUpload>(uploadStr);
                }
            }
            catch (Exception ex)
            {
                _log.LogError(ex.Message);
                code = "100050";
            }
            return(ReturnJson(code, returnUpload));
        }
        public string GetAccessToken()
        {
            ReturnUpload returnUpload   = new ReturnUpload();
            string       configFileName = System.Web.Hosting.HostingEnvironment.MapPath("~/Models/Clientconfiguration.json");
            StreamReader reader         = new StreamReader(configFileName);
            string       json           = reader.ReadToEnd();
            Config       config         = JsonConvert.DeserializeObject <Config>(json);

            BoxConfig boxConfig = new BoxConfig(config.boxAppSettings.clientID, config.boxAppSettings.clientSecret, config.enterpriseID, config.boxAppSettings.appAuth.privateKey, config.boxAppSettings.appAuth.passphrase, config.boxAppSettings.appAuth.publicKeyID);

            try
            {
                BoxJWTAuth boxJWT     = new BoxJWTAuth(boxConfig);
                string     adminToken = boxJWT.AdminToken();

                return(adminToken);
            }
            catch (Exception ex)
            {
                return(ex.Message);
            }
        }