public override UploadResult ShortenURL(string url) { UploadResult result = new UploadResult { URL = url }; if (!string.IsNullOrEmpty(url)) { Dictionary<string, string> arguments = new Dictionary<string, string>(); arguments.Add("version", "2.0.1"); arguments.Add("longUrl", url); arguments.Add("login", APILogin); arguments.Add("apiKey", APIKey); arguments.Add("format", "xml"); result.Response = SendGetRequest(APIURL, arguments); XmlDocument xdoc = new XmlDocument(); xdoc.LoadXml(result.Response); XmlNode xnode = xdoc.SelectSingleNode("bitly/results/nodeKeyVal/shortUrl"); if (xnode != null) { result.ShortenedURL = xnode.InnerText; } } return result; }
public override UploadResult Upload(Stream stream, string fileName) { UploadResult result = new UploadResult(); fileName = Helpers.GetValidURL(fileName); string path = Account.GetSubFolderPath(fileName); using (ftpClient = new FTP(Account, BufferSize)) { ftpClient.ProgressChanged += OnProgressChanged; try { IsUploading = true; ftpClient.UploadData(stream, path); } finally { IsUploading = false; } } if (!stopUpload && Errors.Count == 0) { result.URL = Account.GetUriPath(fileName); } return result; }
public override UploadResult UploadText(string text, string fileName) { UploadResult ur = new UploadResult(); if (!string.IsNullOrEmpty(text)) { if (string.IsNullOrEmpty(APIKey)) { APIKey = "public"; } Dictionary<string, string> arguments = new Dictionary<string, string>(); arguments.Add("key", APIKey); arguments.Add("description", string.Empty); arguments.Add("paste", text); arguments.Add("format", "simple"); arguments.Add("return", "link"); ur.Response = SendPostRequest("http://paste.ee/api", arguments); if (!string.IsNullOrEmpty(ur.Response) && ur.Response.StartsWith("error")) { Errors.Add(ur.Response); } else { ur.URL = ur.Response; } } return ur; }
private UploadResult ParseResult(UploadResult result) { if (result.IsSuccess) { XDocument xd = XDocument.Parse(result.Response); XElement xe = xd.Element("image"); if (xe != null) { string id = xe.GetElementValue("id"); result.URL = "http://twitsnaps.com/snap/" + id; result.ThumbnailURL = "http://twitsnaps.com/thumb/" + id; } else { xe = xd.Element("error"); if (xe != null) { Errors.Add("Error: " + xe.GetElementValue("description")); } } } return result; }
private UploadResult ParseResult(string source) { UploadResult ur = new UploadResult(source); if (!string.IsNullOrEmpty(source)) { XDocument xd = XDocument.Parse(source); XElement xe; xe = xd.Element("image"); if (xe != null) { string id = xe.GetElementValue("id"); ur.URL = "http://twitsnaps.com/snap/" + id; ur.ThumbnailURL = "http://twitsnaps.com/thumb/" + id; } else { xe = xd.Element("error"); if (xe != null) { Errors.Add("Error: " + xe.GetElementValue("description")); } } } return ur; }
public override UploadResult UploadText(string text, string fileName) { UploadResult ur = new UploadResult(); if (!string.IsNullOrEmpty(text) && !string.IsNullOrEmpty(fileName)) { var gistUploadObject = new { @public = true, files = new Dictionary<string, object> { { fileName, new { content = text } } } }; string argsJson = JsonConvert.SerializeObject(gistUploadObject); string response = SendPostRequestJSON(GistUploadUrl, argsJson); if (response != null) { var gistReturnType = new { html_url = "" }; var gistReturnObject = JsonConvert.DeserializeAnonymousType(response, gistReturnType); ur.URL = gistReturnObject.html_url; } } return ur; }
public override UploadResult ShortenURL(string url) { UploadResult result = new UploadResult { URL = url }; if (!string.IsNullOrEmpty(url)) { Dictionary<string, string> arguments = new Dictionary<string, string>(); arguments.Add("url", url); result.Response = SendGetRequest(APIURL, arguments); if (!string.IsNullOrEmpty(result.Response)) { if (result.Response.StartsWith("SUCCESS:")) { result.ShortenedURL = "http://turl.ca/" + result.Response.Substring(8); } if (result.Response.StartsWith("ERROR:")) { Errors.Add(result.Response.Substring(6)); } } } return result; }
public override UploadResult ShortenURL(string url) { if (customUploader.RequestType == CustomUploaderRequestType.POST && !string.IsNullOrEmpty(customUploader.FileFormName)) throw new Exception("'File form name' cannot be used with custom URL shortener."); if (string.IsNullOrEmpty(customUploader.RequestURL)) throw new Exception("'Request URL' must be not empty."); if (customUploader.Arguments == null || !customUploader.Arguments.Any(x => x.Value.Contains("%input") || x.Value.Contains("$input$"))) throw new Exception("Atleast one '%input' or '$input$' required for argument value when using custom URL shortener."); UploadResult result = new UploadResult { URL = url }; customUploader.Input = url; Dictionary<string, string> args = customUploader.ParseArguments(); if (customUploader.RequestType == CustomUploaderRequestType.POST) { result.Response = SendPostRequest(customUploader.RequestURL, args, customUploader.ResponseType); } else if (customUploader.RequestType == CustomUploaderRequestType.GET) { result.Response = SendGetRequest(customUploader.RequestURL, args, customUploader.ResponseType); } if (!string.IsNullOrEmpty(result.Response)) { customUploader.Parse(result.Response); result.ShortenedURL = customUploader.ResultURL; result.ThumbnailURL = customUploader.ResultThumbnailURL; result.DeletionURL = customUploader.ResultDeletionURL; } return result; }
public override UploadResult Upload(Stream stream, string fileName) { string response = UploadData(stream, imageHosting.UploadURL, fileName, imageHosting.FileFormName, imageHosting.GetArguments()); UploadResult result = new UploadResult(response); if (!string.IsNullOrEmpty(response)) { imageHosting.Parse(response); if (!string.IsNullOrEmpty(imageHosting.URL)) { result.URL = imageHosting.GetURL(URLType.URL); } else if (imageHosting.AutoUseResponse) { result.URL = response; } if (!string.IsNullOrEmpty(imageHosting.ThumbnailURL)) { result.ThumbnailURL = imageHosting.GetURL(URLType.ThumbnailURL); } if (!string.IsNullOrEmpty(imageHosting.DeletionURL)) { result.DeletionURL = imageHosting.GetURL(URLType.DeletionURL); } } return result; }
public override UploadResult Upload(Stream stream, string fileName) { UploadResult ur = new UploadResult(); Dictionary<string, string> arguments = new Dictionary<string, string>(); arguments.Add("t", "file"); arguments.Add("name", "ZScreen"); arguments.Add("tags", "zscreen"); arguments.Add("description", "test"); arguments.Add("adult", "t"); arguments.Add("sfile", "Upload"); arguments.Add("url", string.Empty); ur.Source = UploadData(stream, "http://imagebin.ca/upload.php", fileName, "f", arguments); if (!string.IsNullOrEmpty(ur.Source)) { Match match = Regex.Match(ur.Source, @"(?<=ca/view/).+(?=\.html'>)"); if (match != null) { string url = "http://imagebin.ca/img/" + match.Value + Path.GetExtension(fileName); ur.URL = url; } } return ur; }
public override UploadResult Upload(Stream stream, string fileName) { UploadResult ur = new UploadResult(); ur.Source = UploadData(stream, uploadURL, fileName, "fileup"); if (!string.IsNullOrEmpty(ur.Source)) { string lastLine = ur.Source.Remove(0, ur.Source.LastIndexOf('\n') + 1).Trim(); ur.URL = lastLine; } return ur; }
private void TranscodeFile(string key, UploadResult result) { Dictionary<string, string> args = new Dictionary<string, string>(); if (NoResize) args.Add("noResize", "true"); if (IgnoreExisting) args.Add("noMd5", "true"); string url = CreateQuery("https://upload.gfycat.com/transcodeRelease/" + key, args); string transcodeJson = SendRequest(HttpMethod.GET, url); GfycatTranscodeResponse transcodeResponse = JsonConvert.DeserializeObject<GfycatTranscodeResponse>(transcodeJson); if (transcodeResponse.IsOk) { ProgressManager progress = new ProgressManager(10000); if (AllowReportProgress) { OnProgressChanged(progress); } while (!StopUploadRequested) { string statusJson = SendRequest(HttpMethod.GET, "https://upload.gfycat.com/status/" + key); GfycatStatusResponse response = JsonConvert.DeserializeObject<GfycatStatusResponse>(statusJson); if (response.Error != null) { result.Errors.Add(response.Error); result.IsSuccess = false; break; } else if (response.GfyName != null) { result.IsSuccess = true; result.URL = "https://gfycat.com/" + response.GfyName; break; } if (AllowReportProgress && progress.UpdateProgress((progress.Length - progress.Position) / response.Time)) { OnProgressChanged(progress); } Thread.Sleep(100); } } else { result.Errors.Add(transcodeResponse.Error); result.IsSuccess = false; } }
public override UploadResult ShortenURL(string url) { UploadResult result = new UploadResult { URL = url }; if (!string.IsNullOrEmpty(url)) { Dictionary<string, string> arguments = new Dictionary<string, string>(); arguments.Add("url", url); result.Response = result.ShortenedURL = SendGetRequest(APIURL, arguments); } return result; }
public override UploadResult Upload(Stream stream, string fileName) { string response = UploadData(stream, "http://file1.share.cx/cgi-bin/upload.cgi", fileName, "file_0"); UploadResult result = new UploadResult(response); MatchCollection matches = Regex.Matches(response, "(?<=value=\")http:.+?(?=\".*></td>)"); if (matches.Count == 2) { result.URL = matches[0].Value; result.DeletionURL = matches[1].Value; } return result; }
public override UploadResult Upload(Stream stream, string fileName) { Dictionary<string, string> args = new Dictionary<string, string>(); args.Add("MAX_FILE_SIZE", "82428800"); string response = UploadData(stream, "http://filebin.ca/upload.php", fileName, "file", args); UploadResult result = new UploadResult(response); if (!string.IsNullOrEmpty(response)) { result.URL = response.Substring(response.LastIndexOf(' ') + 1).Trim(); } return result; }
private UploadResult ParseResult(string source) { UploadResult ur = new UploadResult(source); if (!string.IsNullOrEmpty(source)) { XDocument xdoc = XDocument.Parse(source); XElement xele = xdoc.Root.Element("upload"); string error = xele.GetElementValue("errorCode"); if (!string.IsNullOrEmpty(error)) { string errorMessage; switch (error) { case "1": errorMessage = "The MD5 sum that you provided did not match the MD5 sum that we calculated for the uploaded image file." + " There may of been a network interruption during upload. Suggest that you try the upload again."; break; case "2": errorMessage = "The apiKey that you provided does not exist or has been banned. Please contact us for more information."; break; case "3": errorMessage = "The file that you provided was not a png or jpg."; break; case "4": errorMessage = "The file that you provided was too large, currently the limit per file is 50MB."; break; case "99": default: errorMessage = "An unkown error occured, please contact the admin and include a copy of the file that you were trying to upload."; break; } Errors.Add(errorMessage); } else { ur.URL = xele.GetElementValue("original"); ur.ThumbnailURL = xele.GetElementValue("small"); ur.DeletionURL = xele.GetElementValue("deleteurl"); } } return ur; }
public override UploadResult Upload(Stream stream, string fileName) { UploadResult result = new UploadResult(); string remotePath = GetRemotePath(fileName); try { stream.Position = 0; if (FTPAccount.Protocol == FTPProtocol.SFTP) { using (SFTP sftpClient = new SFTP(FTPAccount)) { if (!sftpClient.IsInstantiated) { Errors.Add("An SFTP client couldn't be instantiated, not enough information.\r\nCould be a missing key file."); } else { sftpClient.ProgressChanged += new Uploader.ProgressEventHandler(x => OnProgressChanged(x)); sftpClient.UploadData(stream, remotePath); } } } else // FTP or FTPS { using (FTP ftpClient = new FTP(FTPAccount)) { ftpClient.ProgressChanged += new Uploader.ProgressEventHandler(x => OnProgressChanged(x)); ftpClient.UploadData(stream, remotePath); } } } catch (Exception e) { DebugHelper.WriteException(e); Errors.Add(e.Message); } if (Errors.Count == 0) { result.URL = FTPAccount.GetUriPath(fileName); } return result; }
public override UploadResult UploadText(string text, string fileName) { UploadResult ur = new UploadResult(); if (!string.IsNullOrEmpty(text)) { Dictionary<string, string> arguments = new Dictionary<string, string>(); arguments.Add("code", text); arguments.Add("description", settings.Description); arguments.Add("lang", settings.TextFormat); arguments.Add("parent", "0"); ur.URL = SendPostRequest(APIURL, arguments, ResponseType.RedirectionURL); } return ur; }
public override UploadResult Upload(Stream stream, string fileName) { UploadResult result = new UploadResult(); string filePath = account.GetLocalhostPath(fileName); Helpers.CreateDirectoryIfNotExist(filePath); using (FileStream fs = new FileStream(filePath, FileMode.Create)) { if (TransferData(stream, fs)) { result.URL = account.GetUriPath(Path.GetFileName(fileName)); } } return result; }
public override UploadResult UploadText(string text, string fileName) { if (string.IsNullOrEmpty(customUploader.RequestURL)) throw new Exception("'Request URL' must be not empty."); if ((customUploader.RequestType == CustomUploaderRequestType.GET || string.IsNullOrEmpty(customUploader.FileFormName)) && (customUploader.Arguments == null || !customUploader.Arguments.Any(x => x.Value.Contains("%input") || x.Value.Contains("$input$")))) throw new Exception("Atleast one '%input' or '$input$' required for argument value when using GET or non-file POST."); UploadResult result = new UploadResult(); customUploader.Input = text; Dictionary<string, string> args = customUploader.ParseArguments(); if (customUploader.RequestType == CustomUploaderRequestType.POST) { if (string.IsNullOrEmpty(customUploader.FileFormName)) { result.Response = SendPostRequest(customUploader.RequestURL, args, customUploader.ResponseType); } else { byte[] byteArray = Encoding.UTF8.GetBytes(text); using (MemoryStream stream = new MemoryStream(byteArray)) { result = UploadData(stream, customUploader.RequestURL, fileName, customUploader.FileFormName, args); } } } else if (customUploader.RequestType == CustomUploaderRequestType.GET) { result.Response = SendGetRequest(customUploader.RequestURL, args, customUploader.ResponseType); } if (!string.IsNullOrEmpty(result.Response)) { customUploader.Parse(result.Response); result.URL = customUploader.ResultURL; result.ThumbnailURL = customUploader.ResultThumbnailURL; result.DeletionURL = customUploader.ResultDeletionURL; } return result; }
public override UploadResult ShortenURL(string url) { UploadResult result = new UploadResult { URL = url }; if (!string.IsNullOrEmpty(url)) { Dictionary<string, string> arguments = new Dictionary<string, string>(); arguments.Add("format", "xml"); arguments.Add("longUrl", url); arguments.Add("login", APILogin); arguments.Add("apiKey", APIKey); result.Response = SendGetRequest(URLShorten, arguments); XDocument xd = XDocument.Parse(result.Response); result.ShortenedURL = xd.GetValue("response/data/url"); } return result; }
public override UploadResult UploadText(string text, string fileName) { UploadResult ur = new UploadResult(); if (!string.IsNullOrEmpty(text)) { Dictionary<string, string> arguments = new Dictionary<string, string>(); arguments.Add("lexer", Lexer); arguments.Add("content", text); arguments.Add("ttl", (TimeToLive * 86400).ToString()); if (!string.IsNullOrEmpty(Key)) { arguments.Add("encrypt", "checked"); arguments.Add("key", Key); } ur.URL = SendPostRequest("https://pastee.org/submit", arguments, ResponseType.RedirectionURL); } return ur; }
public override UploadResult Upload(Stream stream, string fileName) { UploadResult ur = new UploadResult(); string url = GetUploadURL(); if (!string.IsNullOrEmpty(url)) { ur.Source = UploadData(stream, url, fileName); if (!string.IsNullOrEmpty(ur.Source)) { ur.URL = ur.Source; } } else { Errors.Add("GetUploadURL failed."); } return ur; }
public override UploadResult Upload(Stream stream, string fileName) { UploadResult ur = new UploadResult(); Dictionary<string, string> arguments = new Dictionary<string, string>(); arguments.Add("key", DeveloperKey); arguments.Add("public", IsPublic ? "yes" : "no"); if (AccountType == AccountType.User && !string.IsNullOrEmpty(RegistrationCode)) { arguments.Add("cookie", RegistrationCode); } ur.Source = UploadData(stream, "http://www.imageshack.us/upload_api.php", fileName, "fileupload", arguments); if (!string.IsNullOrEmpty(ur.Source)) { ur.URL = ZAppHelper.GetXMLValue(ur.Source, "image_link"); ur.ThumbnailURL = ZAppHelper.GetXMLValue(ur.Source, "thumb_link"); } return ur; }
public override UploadResult ShortenURL(string url) { UploadResult result = new UploadResult { URL = url }; if (!string.IsNullOrEmpty(url)) { Dictionary<string, string> arguments = new Dictionary<string, string>(); arguments.Add("access_token", AuthInfo.Token.access_token); arguments.Add("longUrl", url); if (!string.IsNullOrEmpty(Domain)) arguments.Add("domain", Domain); result.Response = SendRequest(HttpMethod.GET, URLShorten, arguments); BitlyShortenResponse shorten = JsonConvert.DeserializeObject<BitlyShortenResponse>(result.Response); if (shorten != null && shorten.data != null && !string.IsNullOrEmpty(shorten.data.url)) { result.ShortenedURL = shorten.data.url; } } return result; }
public override UploadResult UploadText(string text, string fileName) { UploadResult ur = new UploadResult(); if (!string.IsNullOrEmpty(text)) { Dictionary<string, string> arguments = new Dictionary<string, string>(); arguments.Add("raw_paste", text); arguments.Add("author", settings.Author); arguments.Add("comment", ""); arguments.Add("desc", settings.Description); arguments.Add("expire", settings.Expiration); arguments.Add("language", settings.TextFormat); arguments.Add("linenumbers", settings.LineNumbers ? "1" : "0"); arguments.Add("permissions", settings.Visibility == Privacy.Private ? "1" : "0"); arguments.Add("submit", "Submit Paste"); arguments.Add("tabbing", "true"); arguments.Add("tabtype", "real"); ur.URL = SendPostRequest(APIURL, arguments, ResponseType.RedirectionURL); } return ur; }
public override UploadResult Upload(Stream stream, string fileName) { UploadResult result = new UploadResult(); if (Connect()) { fileName = Helpers.GetValidURL(fileName); string folderPath = Account.GetSubFolderPath(); string filePath = Helpers.CombineURL(folderPath, fileName); try { IsUploading = true; UploadStream(stream, filePath); } catch (SftpPathNotFoundException) { CreateDirectory(folderPath); UploadStream(stream, filePath); } finally { IsUploading = false; } Disconnect(); if (!stopUpload && Errors.Count == 0) { result.URL = Account.GetUriPath(fileName); } } return result; }
private UploadResult ParseResult(UploadResult result) { if (result.IsSuccess) { XDocument xdoc = XDocument.Parse(result.Response); XElement xele = xdoc.Element("rsp"); if (xele != null) { switch (xele.GetAttributeFirstValue("status", "stat")) { case "ok": string statusid = xele.GetElementValue("statusid"); string userid = xele.GetElementValue("userid"); string mediaid = xele.GetElementValue("mediaid"); string mediaurl = xele.GetElementValue("mediaurl"); if (Options.ShowFull) mediaurl = mediaurl + "/full"; result.URL = mediaurl; result.ThumbnailURL = mediaurl + ".th.jpg"; break; case "fail": string code = xele.Element("err").Attribute("code").Value; string msg = xele.Element("err").Attribute("msg").Value; Errors.Add(msg); break; } } } return result; }
private UploadResult ParseResponse(UploadResult result) { if (result.IsSuccess) { try { XDocument xd = XDocument.Parse(result.Response); XElement xe; if ((xe = xd.GetNode("upload|images/links")) != null) { result.URL = xe.GetElementValue("original"); if (ThumbnailType == ImgurThumbnailType.Large_Thumbnail) { result.ThumbnailURL = xe.GetElementValue("large_thumbnail"); } else { result.ThumbnailURL = xe.GetElementValue("small_square"); } result.DeletionURL = xe.GetElementValue("delete_page"); } else if ((xe = xd.GetElement("error")) != null) { Errors.Add("Imgur error message: " + xe.GetElementValue("message")); } } catch (Exception e) { Errors.Add(e.ToString()); } } return result; }
public override UploadResult UploadText(string text, string fileName) { UploadResult ur = new UploadResult(); if (!string.IsNullOrEmpty(text) && !string.IsNullOrEmpty(fileName)) { var gistUploadObject = new { @public = this.publishPublic, files = new Dictionary<string, object> { { fileName, new { content = text } } } }; string argsJson = JsonConvert.SerializeObject(gistUploadObject); string url = URLGists; if (AuthInfo != null) { url += "?access_token=" + AuthInfo.Token.access_token; } string response = SendPostRequestJSON(url, argsJson); if (response != null) { var gistReturnType = new { html_url = string.Empty }; var gistReturnObject = JsonConvert.DeserializeAnonymousType(response, gistReturnType); ur.URL = gistReturnObject.html_url; } } return ur; }