private RestRequest PrepareUploadSrImg(SubredditsUploadSrImgInput subredditsUploadSrImgInput, string subreddit = null) { RestRequest restRequest = PrepareRequest(Sr(subreddit) + "api/upload_sr_img", Method.POST, "multipart/form-data"); restRequest.AddFileBytes("file", subredditsUploadSrImgInput.file, (!string.IsNullOrWhiteSpace(subredditsUploadSrImgInput.name) ? subredditsUploadSrImgInput.name : "image") + "." + subredditsUploadSrImgInput.img_type); restRequest.AddObject(subredditsUploadSrImgInput); return(restRequest); }
/// <summary> /// Add or replace a subreddit image, custom header logo, custom mobile icon, or custom mobile banner asynchronously. /// If the upload_type value is img, an image for use in the subreddit stylesheet is uploaded with the name specified in name. /// If the upload_type value is header then the image uploaded will be the subreddit's new logo and name will be ignored. /// If the upload_type value is icon then the image uploaded will be the subreddit's new mobile icon and name will be ignored. /// If the upload_type value is banner then the image uploaded will be the subreddit's new mobile banner and name will be ignored. /// For backwards compatibility, if upload_type is not specified, the header field will be used instead: /// If the header field has value 0, then upload_type is img. /// If the header field has value 1, then upload_type is header. /// The img_type field specifies whether to store the uploaded image as a PNG or JPEG. /// Subreddits have a limited number of images that can be in use at any given time. If no image with the specified name already exists, one of the slots will be consumed /// If an image with the specified name already exists, it will be replaced. This does not affect the stylesheet immediately, but will take effect the next time the stylesheet is saved. /// See also: /api/delete_sr_img, /api/delete_sr_header, /api/delete_sr_icon, and /api/delete_sr_banner. /// </summary> /// <param name="subredditsUploadSrImgInput">A valid SubredditsUploadSrImgInput instance</param> /// <param name="subreddit">The subreddit being queried</param> /// <returns>An object containing the resulting image URL and any errors.</returns> public async Task <ImageUploadResult> UploadSrImgAsync(SubredditsUploadSrImgInput subredditsUploadSrImgInput, string subreddit = null) { return(JsonConvert.DeserializeObject <ImageUploadResult>(await ExecuteRequestAsync(PrepareUploadSrImg(subredditsUploadSrImgInput, subreddit)))); }
/// <summary> /// Add or replace a subreddit image, custom header logo, custom mobile icon, or custom mobile banner. /// If the upload_type value is img, an image for use in the subreddit stylesheet is uploaded with the name specified in name. /// If the upload_type value is header then the image uploaded will be the subreddit's new logo and name will be ignored. /// If the upload_type value is icon then the image uploaded will be the subreddit's new mobile icon and name will be ignored. /// If the upload_type value is banner then the image uploaded will be the subreddit's new mobile banner and name will be ignored. /// For backwards compatibility, if upload_type is not specified, the header field will be used instead: /// If the header field has value 0, then upload_type is img. /// If the header field has value 1, then upload_type is header. /// The img_type field specifies whether to store the uploaded image as a PNG or JPEG. /// Subreddits have a limited number of images that can be in use at any given time. If no image with the specified name already exists, one of the slots will be consumed /// If an image with the specified name already exists, it will be replaced. This does not affect the stylesheet immediately, but will take effect the next time the stylesheet is saved. /// See also: /api/delete_sr_img, /api/delete_sr_header, /api/delete_sr_icon, and /api/delete_sr_banner. /// </summary> /// <param name="subredditsUploadSrImgInput">A valid SubredditsUploadSrImgInput instance</param> /// <param name="subreddit">The subreddit being queried</param> /// <returns>An object containing the resulting image URL and any errors.</returns> public ImageUploadResult UploadSrImg(SubredditsUploadSrImgInput subredditsUploadSrImgInput, string subreddit = null) { return(JsonConvert.DeserializeObject <ImageUploadResult>(ExecuteRequest(PrepareUploadSrImg(subredditsUploadSrImgInput, subreddit)))); }