public override UploadResult Upload(Stream stream, string fileName) { UploadResult result = null; if (!string.IsNullOrEmpty(Email) && !string.IsNullOrEmpty(Password)) { NameValueCollection headers = UploadHelpers.CreateAuthenticationHeader(Email, Password); result = SendRequestFile("https://api.hostr.co/file", stream, fileName, headers: headers); if (result.IsSuccess) { HostrFileUploadResponse response = JsonConvert.DeserializeObject <HostrFileUploadResponse>(result.Response); if (response != null) { if (DirectURL && response.direct != null) { result.URL = string.Format("http://hostr.co/file/{0}/{1}", response.id, response.name); result.ThumbnailURL = response.direct.direct_150x; } else { result.URL = response.href; } } } } return(result); }
public override UploadResult UploadText(string text, string fileName) { UploadResult result = new UploadResult(); if (!string.IsNullOrEmpty(text)) { Dictionary <string, string> args = new Dictionary <string, string>(); args.Add("secret", text); NameValueCollection headers = null; if (!string.IsNullOrEmpty(API_USERNAME) && !string.IsNullOrEmpty(API_KEY)) { headers = UploadHelpers.CreateAuthenticationHeader(API_USERNAME, API_KEY); } result.Response = SendRequestMultiPart(API_ENDPOINT, args, headers); if (!string.IsNullOrEmpty(result.Response)) { OneTimeSecretResponse jsonResponse = JsonConvert.DeserializeObject <OneTimeSecretResponse>(result.Response); if (jsonResponse != null) { result.URL = URLHelpers.CombineURL("https://onetimesecret.com/secret/", jsonResponse.secret_key); } } } return(result); }
public override UploadResult Upload(Stream stream, string fileName) { if (string.IsNullOrEmpty(Host)) { throw new Exception("ownCloud Host is empty."); } if (string.IsNullOrEmpty(Username) || string.IsNullOrEmpty(Password)) { throw new Exception("ownCloud Username or Password is empty."); } if (string.IsNullOrEmpty(Path)) { Path = "/"; } // Original, unencoded path. Necessary for shared files string path = URLHelpers.CombineURL(Path, fileName); // Encoded path, necessary when sent in the URL string encodedPath = URLHelpers.CombineURL(Path, URLHelpers.URLEncode(fileName)); string url = URLHelpers.CombineURL(Host, "remote.php/webdav", encodedPath); url = URLHelpers.FixPrefix(url); NameValueCollection headers = UploadHelpers.CreateAuthenticationHeader(Username, Password); headers["OCS-APIREQUEST"] = "true"; string response = SendRequest(HttpMethod.PUT, url, stream, UploadHelpers.GetMimeType(fileName), null, headers); UploadResult result = new UploadResult(response); if (!IsError) { if (CreateShare) { AllowReportProgress = false; result.URL = ShareFile(path); } else { result.IsURLExpected = false; } } return(result); }
public override UploadResult Upload(Stream stream, string fileName) { NameValueCollection headers = null; if (!string.IsNullOrEmpty(Email) && !string.IsNullOrEmpty(Password)) { headers = UploadHelpers.CreateAuthenticationHeader(Email, Password); } UploadResult result = SendRequestFile(URLHelpers.CombineURL(Host, "upload"), stream, fileName, headers: headers); TranscodeFile(result); return(result); }
public List <PushbulletDevice> GetDeviceList() { NameValueCollection headers = UploadHelpers.CreateAuthenticationHeader(Config.UserAPIKey, ""); string response = SendRequest(HttpMethod.GET, apiGetDevicesURL, headers: headers); PushbulletResponseDevices devicesResponse = JsonConvert.DeserializeObject <PushbulletResponseDevices>(response); if (devicesResponse != null && devicesResponse.devices != null) { return(devicesResponse.devices.Select(x => new PushbulletDevice { Key = x.iden, Name = x.nickname }).ToList()); } return(new List <PushbulletDevice>()); }
public string ShareFile(string path) { Dictionary <string, string> args = new Dictionary <string, string>(); args.Add("path", path); // path to the file/folder which should be shared args.Add("shareType", "3"); // ‘0’ = user; ‘1’ = group; ‘3’ = public link // args.Add("shareWith", ""); // user / group id with which the file should be shared // args.Add("publicUpload", "false"); // allow public upload to a public shared folder (true/false) // args.Add("password", ""); // password to protect public link Share with args.Add("permissions", "1"); // 1 = read; 2 = update; 4 = create; 8 = delete; 16 = share; 31 = all (default: 31, for public shares: 1) string url = URLHelpers.CombineURL(BaseURL, Filename); url = URLHelpers.FixPrefix(url); NameValueCollection headers = UploadHelpers.CreateAuthenticationHeader(Username, Password); headers["OCS-APIREQUEST"] = "true"; string response = SendRequestMultiPart(url, args, headers); if (!string.IsNullOrEmpty(response)) { PutWebDavShareResponse result = JsonConvert.DeserializeObject <PutWebDavShareResponse>(response); if (result != null && result.ocs != null && result.ocs.meta != null) { if (result.ocs.data != null && result.ocs.meta.statuscode == 100) { PutWebDavShareResponseData data = ((JObject)result.ocs.data).ToObject <PutWebDavShareResponseData>(); string link = data.url; return(link); } else { Errors.Add(string.Format("Status: {0}\r\nStatus code: {1}\r\nMessage: {2}", result.ocs.meta.status, result.ocs.meta.statuscode, result.ocs.meta.message)); } } } return(null); }
/// <summary> /// Attempts to authorize against the B2 API with the given key. /// </summary> /// <param name="keyId">The application key ID <b>or</b> account ID.</param> /// <param name="key">The application key <b>or</b> account master key.</param> /// <param name="error">Will be set to a non-null value on failure.</param> /// <returns>Null if an error occurs, and <c>error</c> will contain an error message. Otherwise, a <see cref="B2Authorization"/>.</returns> private B2Authorization B2ApiAuthorize(string keyId, string key, out string error) { NameValueCollection headers = UploadHelpers.CreateAuthenticationHeader(keyId, key); using (HttpWebResponse res = GetResponse(HttpMethod.GET, B2AuthorizeAccountUrl, headers: headers, allowNon2xxResponses: true)) { if (res.StatusCode != HttpStatusCode.OK) { error = StringifyB2Error(res); return(null); } string body = UploadHelpers.ResponseToString(res); error = null; return(JsonConvert.DeserializeObject <B2Authorization>(body)); } }
private string Push(string pushType, string valueType, string value, string title) { NameValueCollection headers = UploadHelpers.CreateAuthenticationHeader(Config.UserAPIKey, ""); Dictionary <string, string> args = new Dictionary <string, string>(); args.Add("device_iden", Config.CurrentDevice.Key); args.Add("type", pushType); args.Add("title", title); args.Add(valueType, value); if (valueType != "body") { if (pushType == "link") { args.Add("body", value); } else { args.Add("body", "Sent via ShareX"); } } string response = SendRequestMultiPart(apiSendPushURL, args, headers); if (response == null) { return(null); } PushbulletResponsePush push = JsonConvert.DeserializeObject <PushbulletResponsePush>(response); if (push != null) { return(wwwPushesURL + "?push_iden=" + push.iden); } return(null); }
// https://doc.owncloud.org/server/10.0/developer_manual/core/ocs-share-api.html#create-a-new-share public string ShareFile(string path) { Dictionary <string, string> args = new Dictionary <string, string>(); args.Add("path", path); // path to the file/folder which should be shared args.Add("shareType", "3"); // ‘0’ = user; ‘1’ = group; ‘3’ = public link // args.Add("shareWith", ""); // user / group id with which the file should be shared // args.Add("publicUpload", "false"); // allow public upload to a public shared folder (true/false) // args.Add("password", ""); // password to protect public link Share with args.Add("permissions", "1"); // 1 = read; 2 = update; 4 = create; 8 = delete; 16 = share; 31 = all (default: 31, for public shares: 1) if (AutoExpire) { if (AutoExpireTime == 0) { throw new Exception("ownCloud Auto Epxire Time is not valid."); } else { try { DateTime expireTime = DateTime.UtcNow.AddDays(AutoExpireTime); args.Add("expireDate", $"{expireTime.Year}-{expireTime.Month}-{expireTime.Day}"); } catch { throw new Exception("ownCloud Auto Expire time is invalid"); } } } string url = URLHelpers.CombineURL(Host, "ocs/v1.php/apps/files_sharing/api/v1/shares?format=json"); url = URLHelpers.FixPrefix(url); NameValueCollection headers = UploadHelpers.CreateAuthenticationHeader(Username, Password); headers["OCS-APIREQUEST"] = "true"; string response = SendRequestMultiPart(url, args, headers); if (!string.IsNullOrEmpty(response)) { OwnCloudShareResponse result = JsonConvert.DeserializeObject <OwnCloudShareResponse>(response); if (result != null && result.ocs != null && result.ocs.meta != null) { if (result.ocs.data != null && result.ocs.meta.statuscode == 100) { OwnCloudShareResponseData data = ((JObject)result.ocs.data).ToObject <OwnCloudShareResponseData>(); string link = data.url; if (PreviewLink && Helpers.IsImageFile(path)) { link += "/preview"; } else if (DirectLink) { link += (IsCompatibility81 ? "/" : "&") + "download"; } return(link); } else { Errors.Add(string.Format("Status: {0}\r\nStatus code: {1}\r\nMessage: {2}", result.ocs.meta.status, result.ocs.meta.statuscode, result.ocs.meta.message)); } } } return(null); }
public UploadResult PushFile(Stream stream, string fileName) { NameValueCollection headers = UploadHelpers.CreateAuthenticationHeader(Config.UserAPIKey, ""); Dictionary <string, string> pushArgs, upArgs = new Dictionary <string, string>(); upArgs.Add("file_name", fileName); string uploadRequest = SendRequestMultiPart(apiRequestFileUploadURL, upArgs, headers); if (uploadRequest == null) { return(null); } PushbulletResponseFileUpload fileInfo = JsonConvert.DeserializeObject <PushbulletResponseFileUpload>(uploadRequest); if (fileInfo == null) { return(null); } pushArgs = upArgs; upArgs = new Dictionary <string, string>(); upArgs.Add("awsaccesskeyid", fileInfo.data.awsaccesskeyid); upArgs.Add("acl", fileInfo.data.acl); upArgs.Add("key", fileInfo.data.key); upArgs.Add("signature", fileInfo.data.signature); upArgs.Add("policy", fileInfo.data.policy); upArgs.Add("content-type", fileInfo.data.content_type); UploadResult uploadResult = SendRequestFile(fileInfo.upload_url, stream, fileName, "file", upArgs); if (uploadResult == null) { return(null); } pushArgs.Add("device_iden", Config.CurrentDevice.Key); pushArgs.Add("type", "file"); pushArgs.Add("file_url", fileInfo.file_url); pushArgs.Add("body", "Sent via ShareX"); string pushResult = SendRequestMultiPart(apiSendPushURL, pushArgs, headers); if (pushResult == null) { return(null); } PushbulletResponsePush push = JsonConvert.DeserializeObject <PushbulletResponsePush>(pushResult); if (push != null) { uploadResult.URL = wwwPushesURL + "?push_iden=" + push.iden; } return(uploadResult); }