public async Task <JSON_FileMetadata> CopyThumbnail(long DestinationFolderID, string WIDTH_x_HEIGHT, ExtEnum Ext, bool Crop, bool AutoRename, string RenameTo = null) { var parameters = new AuthDictionary { { "fileid", FileID.ToString() }, { "tofolderid", DestinationFolderID.ToString() }, { "noover", AutoRename ? "1" : null }, { "toname", RenameTo }, { "type", Ext.ToString() }, { "size", WIDTH_x_HEIGHT }, { "crop", Crop ? "1" : null } }; var encodedContent = new FormUrlEncodedContent(parameters.RemoveEmptyValues()); using (HtpClient localHttpClient = new HtpClient(new HCHandler())) { HttpRequestMessage HtpReqMessage = new HttpRequestMessage(HttpMethod.Post, new pUri("/savethumb")); HtpReqMessage.Content = encodedContent; using (HttpResponseMessage response = await localHttpClient.SendAsync(HtpReqMessage, HttpCompletionOption.ResponseContentRead).ConfigureAwait(false)) { string result = await response.Content.ReadAsStringAsync(); if (response.StatusCode == HttpStatusCode.OK && JObject.Parse(result).Value <int>("result").Equals(0)) { return(JsonConvert.DeserializeObject <JSON_FileMetadata>(JObject.Parse(result).SelectToken("metadata").ToString(), JSONhandler)); } else { ShowError(result); return(null); } } } }
public async Task <byte[]> Thumbnail(string WIDTH_x_HEIGHT, ExtEnum Ext, bool Crop) { var parameters = new AuthDictionary() { { "fileid", FileID.ToString() }, { "size", WIDTH_x_HEIGHT }, { "type", Ext.ToString() }, { "crop", Crop ? "1" : null } }; using (HtpClient localHttpClient = new HtpClient(new HCHandler())) { HttpRequestMessage HtpReqMessage = new HttpRequestMessage(HttpMethod.Post, new pUri("/getthumb")); HtpReqMessage.Content = new FormUrlEncodedContent(parameters.RemoveEmptyValues()); using (HttpResponseMessage response = await localHttpClient.SendAsync(HtpReqMessage, HttpCompletionOption.ResponseContentRead).ConfigureAwait(false)) { if (response.StatusCode == HttpStatusCode.OK) { return(await response.Content.ReadAsByteArrayAsync()); } else { throw new pCloudException(response.ReasonPhrase, (int)response.StatusCode); } } } }
public async Task <string> ThumbnailUrl(string WIDTH_x_HEIGHT, ExtEnum Ext, bool Crop) { var parameters = new AuthDictionary() { { "fileid", FileID.ToString() }, { "size", WIDTH_x_HEIGHT }, { "type", Ext.ToString() }, { "crop", Crop ? "1" : null } }; using (HtpClient localHttpClient = new HtpClient(new HCHandler())) { HttpRequestMessage HtpReqMessage = new HttpRequestMessage(HttpMethod.Post, new pUri("/getthumblink")); HtpReqMessage.Content = new FormUrlEncodedContent(parameters.RemoveEmptyValues()); using (HttpResponseMessage response = await localHttpClient.SendAsync(HtpReqMessage, HttpCompletionOption.ResponseContentRead).ConfigureAwait(false)) { string result = await response.Content.ReadAsStringAsync(); if (response.StatusCode == HttpStatusCode.OK && JObject.Parse(result).Value <int>("result").Equals(0)) { return(string.Format("https://{0}{1}", JObject.Parse(result).SelectToken("hosts[0]").ToString(), JObject.Parse(result).SelectToken("path").ToString().Replace(@"\", string.Empty))); } else { ShowError(result); return(null); } } } }
public async Task <Dictionary <long, string> > ThumbnailUrl(string WIDTH_x_HEIGHT, ExtEnum Ext, bool Crop) { var parameters = new AuthDictionary() { { "fileids", string.Join(",", FileIDs) }, { "size", WIDTH_x_HEIGHT }, { "type", Ext.ToString() } }; if (Crop) { parameters.Add("crop", "1"); } using (HtpClient localHttpClient = new HtpClient(new HCHandler())) { HttpRequestMessage HtpReqMessage = new HttpRequestMessage(HttpMethod.Post, new pUri("/getthumbslinks")); HtpReqMessage.Content = new FormUrlEncodedContent(parameters); using (HttpResponseMessage response = await localHttpClient.SendAsync(HtpReqMessage, HttpCompletionOption.ResponseContentRead).ConfigureAwait(false)) { string result = await response.Content.ReadAsStringAsync(); if (response.StatusCode == HttpStatusCode.OK && JObject.Parse(result).Value <int>("result").Equals(0)) { Dictionary <long, string> addationStatus = new Dictionary <long, string>(); JObject.Parse(result).SelectToken("thumbs").ToList().ForEach(x => addationStatus.Add(x.Value <long>("fileid"), x.Value <int>("result").Equals(0) ? string.Format("https://{0}{1}", x.SelectToken("hosts").ToList().First(), x.Value <string>("path")) : x.Value <string>("error"))); return(addationStatus); } else { ShowError(result); return(null); } } } }