Esempio n. 1
0
        public void UploadHeaderImage(string name, ImageType imageType, byte[] file)
        {
            var request  = WebAgent.CreatePost(UploadImageUrl);
            var formData = new MultipartFormBuilder(request);

            formData.AddDynamic(new
            {
                name,
                uh       = Reddit.User.Modhash,
                r        = Name,
                formid   = "image-upload",
                img_type = imageType == ImageType.PNG ? "png" : "jpg",
                upload   = "",
                header   = 1
            });
            formData.AddFile("file", "foo.png", file, imageType == ImageType.PNG ? "image/png" : "image/jpeg");
            formData.Finish();
            var response = request.GetResponse();
            var data     = WebAgent.GetResponseString(response.GetResponseStream());
            // TODO: Detect errors
        }
Esempio n. 2
0
        /// <summary>
        /// Upload a header image.
        /// </summary>
        /// <param name="name">name of image.</param>
        /// <param name="imageType"><see cref="ImageType"/> of image</param>
        /// <param name="file">image buffer</param>
        public async Task UploadHeaderImageAsync(string name, ImageType imageType, byte[] file)
        {
            var request  = WebAgent.CreateRequest(UploadImageUrl, "POST");
            var formData = new MultipartFormBuilder(request);

            formData.AddDynamic(new
            {
                name,
                r        = Name,
                formid   = "image-upload",
                img_type = imageType == ImageType.PNG ? "png" : "jpg",
                upload   = "",
                header   = 1
            });
            formData.AddFile("file", "foo.png", file, imageType == ImageType.PNG ? "image/png" : "image/jpeg");
            formData.Finish();
            var response = await WebAgent.GetResponseAsync(request).ConfigureAwait(false);

            var data = await response.Content.ReadAsStringAsync().ConfigureAwait(false);

            // TODO: Detect errors
        }
Esempio n. 3
0
 public void UploadHeaderImage(string name, ImageType imageType, byte[] file)
 {
     var request = WebAgent.CreatePost(UploadImageUrl);
     var formData = new MultipartFormBuilder(request);
     formData.AddDynamic(new
     {
         name,
         uh = Reddit.User.Modhash,
         r = Name,
         formid = "image-upload",
         img_type = imageType == ImageType.PNG ? "png" : "jpg",
         upload = "",
         header = 1
     });
     formData.AddFile("file", "foo.png", file, imageType == ImageType.PNG ? "image/png" : "image/jpeg");
     formData.Finish();
     var response = request.GetResponse();
     var data = WebAgent.GetResponseString(response.GetResponseStream());
     // TODO: Detect errors
 }