示例#1
0
        // Return access link of image
        // UserOrLandImage can be "avatar" or "land" to access folder
        public string PostImage(Bitmap bitmap, string AvatarOrLandImage)
        {
            string albumHash;

            if (AvatarOrLandImage.ToLower().Equals("avatar"))
            {
                albumHash = "JqYSF";
            }
            else if (AvatarOrLandImage.ToLower().Equals("land"))
            {
                albumHash = "ff15H";
            }
            else
            {
                return("Invalid AvatarOrLandImage");
            }
            string imageBase64 = BitmapHelper.BitmapToBase64(bitmap);
            string accessToken = GenerateImgurAccessToken();

            RestClient  client  = new RestClient(imgurApi);
            RestRequest request = new RestRequest("3/image", Method.POST);

            request.AddHeader("Authorization", "Bearer " + accessToken);
            request.AddParameter("image", imageBase64);
            request.AddParameter("album", albumHash);
            request.AddParameter("type", "base64");

            var response = client.Execute <ImgurResponseModel>(request);

            if (response.Data.success)
            {
                return(response.Data.data.link);
            }
            return("Error when upload image!");
        }