Exemplo n.º 1
0
        /// <summary>
        /// 下载图片
        /// </summary>
        /// <param name="id"></param>
        /// <param name="countryId"></param>
        /// <returns></returns>
        public string Download(string id, int countryId)
        {
            if (string.IsNullOrWhiteSpace(id))
            {
                throw new CommonException(ReasonCode.FiiiPosReasonCode.NO_IMAGE, "获取不到图片");
            }

            var bytes = new RegionImageAgent(countryId).Download(id);

            if (bytes == null)
            {
                throw new CommonException(ReasonCode.FiiiPosReasonCode.NO_IMAGE, "获取不到图片");
            }
            string imageData = Convert.ToBase64String(bytes);

            if (string.IsNullOrEmpty(imageData))
            {
                throw new CommonException(ReasonCode.FiiiPosReasonCode.NO_IMAGE, "获取不到图片");
            }
            return(imageData);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 图片上传到Region的服务器
        /// </summary>
        /// <param name="fileName">Name of the file.</param>
        /// <param name="base64Content">Content of the base64.</param>
        /// <param name="countryId">The country identifier.</param>
        /// <returns></returns>
        /// <exception cref="ApplicationException">
        /// </exception>
        public string UploadWithRegion(string fileName, string base64Content, int countryId)
        {
            var bytes = Convert.FromBase64String(base64Content);

            try
            {
                var ms = new MemoryStream(bytes);
                Image.FromStream(ms);
            }
            catch
            {
                throw new ApplicationException(MessageResources.InvalidFormat);
            }

            var imgId = new RegionImageAgent(countryId).Upload(fileName ?? Guid.NewGuid().ToString(), bytes);

            if (string.IsNullOrEmpty(imgId))
            {
                throw new ApplicationException(MessageResources.UploadFailed);
            }

            return(imgId);
        }