public string CreateShareableLink(string path, DropboxURLType urlType) { if (!string.IsNullOrEmpty(path) && OAuth2Info.CheckOAuth(AuthInfo)) { string json = JsonConvert.SerializeObject(new { path = VerifyPath(path), settings = new { requested_visibility = "public" // Anyone who has received the link can access it. No login required. } }); string response = SendRequestJSON(URLCreateSharedLink, json, GetAuthHeaders()); if (!string.IsNullOrEmpty(response)) { DropboxLinkMetadata linkMetadata = JsonConvert.DeserializeObject <DropboxLinkMetadata>(response); if (urlType == DropboxURLType.Direct) { return(GetDirectShareableURL(linkMetadata.url)); } else { return(linkMetadata.url); } } } return(null); }
public string CreateShareableLinkAPIv1(string path, DropboxURLType urlType) { if (!string.IsNullOrEmpty(path) && OAuth2Info.CheckOAuth(AuthInfo)) { string url = URLHelpers.CombineURL(URLShares, URLHelpers.URLPathEncode(path)); Dictionary <string, string> args = new Dictionary <string, string>(); args.Add("short_url", urlType == DropboxURLType.Shortened ? "true" : "false"); string response = SendRequest(HttpMethod.POST, url, args, GetAuthHeaders()); if (!string.IsNullOrEmpty(response)) { DropboxShares shares = JsonConvert.DeserializeObject <DropboxShares>(response); if (urlType == DropboxURLType.Direct) { return(GetDirectShareableURL(shares.URL)); } else { return(shares.URL); } } } return(null); }
public string CreateShareableLink(string path, DropboxURLType urlType) { if (!string.IsNullOrEmpty(path) && OAuth2Info.CheckOAuth(AuthInfo)) { string json = JsonConvert.SerializeObject(new { path = VerifyPath(path), settings = new { requested_visibility = "public" // Anyone who has received the link can access it. No login required. } }); // TODO: Missing: args.Add("short_url", urlType == DropboxURLType.Shortened ? "true" : "false"); string response = SendRequestJSON(URLCreateSharedLink, json, GetAuthHeaders()); if (!string.IsNullOrEmpty(response)) { DropboxLinkMetadata linkMetadata = JsonConvert.DeserializeObject <DropboxLinkMetadata>(response); if (urlType == DropboxURLType.Direct) { Match match = Regex.Match(linkMetadata.url, @"https?://(?:www\.)?dropbox.com/s/(?<path>\w+/.+)"); if (match.Success) { string urlPath = match.Groups["path"].Value; if (!string.IsNullOrEmpty(urlPath)) { return(URLHelpers.CombineURL(URLShareDirect, urlPath)); } } } else { return(linkMetadata.url); } } } return(null); }
// https://www.dropbox.com/developers/core/api#shares public string CreateShareableLink(string path, DropboxURLType urlType) { if (!string.IsNullOrEmpty(path) && OAuthInfo.CheckOAuth(AuthInfo)) { string url = Helpers.CombineURL(URLShares, Helpers.URLPathEncode(path)); Dictionary <string, string> args = new Dictionary <string, string>(); args.Add("short_url", urlType == DropboxURLType.Shortened ? "true" : "false"); string query = OAuthManager.GenerateQuery(url, args, HttpMethod.POST, AuthInfo); string response = SendRequest(HttpMethod.POST, query); if (!string.IsNullOrEmpty(response)) { DropboxShares shares = JsonConvert.DeserializeObject <DropboxShares>(response); if (urlType == DropboxURLType.Direct) { Match match = Regex.Match(shares.URL, @"https?://(?:www\.)?dropbox.com/s/(?<path>\w+/.+)"); if (match.Success) { string urlPath = match.Groups["path"].Value; if (!string.IsNullOrEmpty(urlPath)) { return(Helpers.CombineURL(URLShareDirect, urlPath)); } } } else { return(shares.URL); } } } return(null); }
// https://www.dropbox.com/developers/core/docs#files_put public UploadResult UploadFile(Stream stream, string path, string fileName, bool createShareableURL = false, DropboxURLType urlType = DropboxURLType.Default) { if (!OAuth2Info.CheckOAuth(AuthInfo)) { Errors.Add("Dropbox login is required."); return(null); } string url = URLHelpers.CombineURL(URLFiles, URLHelpers.URLPathEncode(path)); // There's a 150MB limit to all uploads through the API. UploadResult result = UploadData(stream, url, fileName, headers: GetAuthHeaders()); if (result.IsSuccess) { DropboxContentInfo content = JsonConvert.DeserializeObject <DropboxContentInfo>(result.Response); if (content != null) { if (createShareableURL) { AllowReportProgress = false; result.URL = CreateShareableLink(content.Path, urlType); } else { result.URL = GetPublicURL(content.Path); } } } return(result); }
public string CreateShareableLinkAPIv1(string path, DropboxURLType urlType) { if (!string.IsNullOrEmpty(path) && OAuth2Info.CheckOAuth(AuthInfo)) { string url = URLHelpers.CombineURL(URLShares, URLHelpers.URLPathEncode(path)); Dictionary<string, string> args = new Dictionary<string, string>(); args.Add("short_url", urlType == DropboxURLType.Shortened ? "true" : "false"); string response = SendRequest(HttpMethod.POST, url, args, GetAuthHeaders()); if (!string.IsNullOrEmpty(response)) { DropboxShares shares = JsonConvert.DeserializeObject<DropboxShares>(response); if (urlType == DropboxURLType.Direct) { return GetDirectShareableURL(shares.URL); } else { return shares.URL; } } } return null; }
public string CreateShareableLink(string path, DropboxURLType urlType) { if (!string.IsNullOrEmpty(path) && OAuth2Info.CheckOAuth(AuthInfo)) { string json = JsonConvert.SerializeObject(new { path = VerifyPath(path), settings = new { requested_visibility = "public" // Anyone who has received the link can access it. No login required. } }); string response = SendRequestJSON(URLCreateSharedLink, json, GetAuthHeaders()); if (!string.IsNullOrEmpty(response)) { DropboxLinkMetadata linkMetadata = JsonConvert.DeserializeObject<DropboxLinkMetadata>(response); if (urlType == DropboxURLType.Direct) { return GetDirectShareableURL(linkMetadata.url); } else { return linkMetadata.url; } } } return null; }
public UploadResult UploadFile(Stream stream, string path, string filename, bool createShareableURL = false, DropboxURLType urlType = DropboxURLType.Default) { if (stream.Length > 150000000) { Errors.Add("There's a 150MB limit to uploads through the API."); return null; } NameValueCollection headers = GetAuthHeaders(); string json = JsonConvert.SerializeObject(new { path = VerifyPath(path, filename), mode = "overwrite", autorename = false, mute = true }); headers.Add("Dropbox-API-Arg", json); string response = SendRequestStream(URLUpload, stream, ContentTypeOctetStream, headers); UploadResult ur = new UploadResult(response); if (!string.IsNullOrEmpty(ur.Response)) { DropboxMetadata metadata = JsonConvert.DeserializeObject<DropboxMetadata>(ur.Response); if (metadata != null) { if (createShareableURL) { AllowReportProgress = false; ur.URL = CreateShareableLinkAPIv1(metadata.path_display, urlType); } else { ur.URL = GetPublicURL(metadata.path_display); } } } return ur; }
public UploadResult UploadFile(Stream stream, string path, string filename, bool createShareableURL = false, DropboxURLType urlType = DropboxURLType.Default) { if (stream.Length > 150000000) { Errors.Add("There's a 150MB limit to uploads through the API."); return(null); } NameValueCollection headers = GetAuthHeaders(); string json = JsonConvert.SerializeObject(new { path = VerifyPath(path, filename), mode = "overwrite", autorename = false, mute = true }); headers.Add("Dropbox-API-Arg", json); string response = SendRequestStream(URLUpload, stream, ContentTypeOctetStream, headers); UploadResult ur = new UploadResult(response); if (!string.IsNullOrEmpty(ur.Response)) { DropboxMetadata metadata = JsonConvert.DeserializeObject <DropboxMetadata>(ur.Response); if (metadata != null) { if (createShareableURL) { AllowReportProgress = false; ur.URL = CreateShareableLinkAPIv1(metadata.path_display, urlType); } else { ur.URL = GetPublicURL(metadata.path_display); } } } return(ur); }
// https://www.dropbox.com/developers/core/docs#shares public string CreateShareableLink(string path, DropboxURLType urlType) { if (!string.IsNullOrEmpty(path) && OAuth2Info.CheckOAuth(AuthInfo)) { string url = URLHelpers.CombineURL(URLShares, URLHelpers.URLPathEncode(path)); Dictionary<string, string> args = new Dictionary<string, string>(); args.Add("short_url", urlType == DropboxURLType.Shortened ? "true" : "false"); string response = SendRequest(HttpMethod.POST, url, args, GetAuthHeaders()); if (!string.IsNullOrEmpty(response)) { DropboxShares shares = JsonConvert.DeserializeObject<DropboxShares>(response); if (urlType == DropboxURLType.Direct) { Match match = Regex.Match(shares.URL, @"https?://(?:www\.)?dropbox.com/s/(?<path>\w+/.+)"); if (match.Success) { string urlPath = match.Groups["path"].Value; if (!string.IsNullOrEmpty(urlPath)) { return URLHelpers.CombineURL(URLShareDirect, urlPath); } } } else { return shares.URL; } } } return null; }
// https://www.dropbox.com/developers/core/docs#files_put public UploadResult UploadFile(Stream stream, string path, string fileName, bool createShareableURL = false, DropboxURLType urlType = DropboxURLType.Default) { string url = URLHelpers.CombineURL(URLFiles, URLHelpers.URLPathEncode(path)); // There's a 150MB limit to all uploads through the API. UploadResult result = UploadData(stream, url, fileName, headers: GetAuthHeaders()); if (result.IsSuccess) { DropboxContentInfo content = JsonConvert.DeserializeObject<DropboxContentInfo>(result.Response); if (content != null) { if (createShareableURL) { AllowReportProgress = false; result.URL = CreateShareableLink(content.Path, urlType); } else { result.URL = GetPublicURL(content.Path); } } } return result; }
// https://www.dropbox.com/developers/core/api#files-POST public UploadResult UploadFile(Stream stream, string path, string fileName, bool createShareableURL = false, DropboxURLType urlType = DropboxURLType.Default) { if (!OAuthInfo.CheckOAuth(AuthInfo)) { Errors.Add("Dropbox login is required."); return(null); } string url = Helpers.CombineURL(URLFiles, Helpers.URLPathEncode(path)); Dictionary <string, string> args = new Dictionary <string, string>(); args.Add("file", fileName); string query = OAuthManager.GenerateQuery(url, args, HttpMethod.POST, AuthInfo); // There's a 150MB limit to all uploads through the API. UploadResult result = UploadData(stream, query, fileName); if (result.IsSuccess) { DropboxContentInfo content = JsonConvert.DeserializeObject <DropboxContentInfo>(result.Response); if (content != null) { if (createShareableURL) { result.URL = CreateShareableLink(content.Path, urlType); } else { result.URL = GetPublicURL(content.Path); } } } return(result); }
// https://www.dropbox.com/developers/core/api#files-POST public UploadResult UploadFile(Stream stream, string path, string fileName, bool createShareableURL = false, DropboxURLType urlType = DropboxURLType.Default) { if (!OAuthInfo.CheckOAuth(AuthInfo)) { Errors.Add("Dropbox login is required."); return null; } string url = Helpers.CombineURL(URLFiles, Helpers.URLPathEncode(path)); Dictionary<string, string> args = new Dictionary<string, string>(); args.Add("file", fileName); string query = OAuthManager.GenerateQuery(url, args, HttpMethod.POST, AuthInfo); // There's a 150MB limit to all uploads through the API. UploadResult result = UploadData(stream, query, fileName); if (result.IsSuccess) { DropboxContentInfo content = JsonConvert.DeserializeObject<DropboxContentInfo>(result.Response); if (content != null) { if (createShareableURL) { result.URL = CreateShareableLink(content.Path, urlType); } else { result.URL = GetPublicURL(content.Path); } } } return result; }