/// <summary>
        /// Creates and returns a shareable link to files or folders.
        /// Note: Links created by the /shares API call expire after thirty days.
        /// </summary>
        /// <returns>
        /// A shareable link to the file or folder. The link can be used publicly and directs to a preview page of the file.
        /// Also returns the link's expiration date in Dropbox's usual date format.
        /// </returns>
        public DropboxShares CreateShareableLink(string path, string fileName = "")
        {
            if (OAuthInfo.CheckOAuth(AuthInfo))
            {
                string url = OAuthManager.GenerateQuery(ZAppHelper.CombineURL(URLShares, path, fileName), null, HttpMethod.Get, AuthInfo);

                string response = SendGetRequest(url);

                if (!string.IsNullOrEmpty(response))
                {
                    DropboxShares shares = JsonConvert.DeserializeObject <DropboxShares>(response);
                    return(shares);
                }
            }

            return(null);
        }
Beispiel #2
0
        // https://www.dropbox.com/developers/core/api#files-POST
        public UploadResult UploadFile(Stream stream, string path, string fileName, bool createShareableURL = false, bool shortURL = true)
        {
            if (!OAuthInfo.CheckOAuth(AuthInfo))
            {
                Errors.Add("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)
                    {
                        DropboxShares shares = CreateShareableLink(content.Path, shortURL);

                        if (shares != null)
                        {
                            result.URL = shares.URL;
                        }
                    }
                    else
                    {
                        result.URL = GetPublicURL(content.Path);
                    }
                }
            }

            return(result);
        }
        public override UploadResult Upload(Stream stream, string fileName)
        {
            if (AuthInfo == null || string.IsNullOrEmpty(AuthInfo.UserToken) || string.IsNullOrEmpty(AuthInfo.UserSecret))
            {
                Errors.Add("Login is required.");
                return(null);
            }

            string url = ZAppHelper.CombineURL(URLFiles, UploadPath);

            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.
            string response = UploadData(stream, query, fileName);

            UploadResult result = new UploadResult(response);

            if (!string.IsNullOrEmpty(response))
            {
                if (AutoCreateShareableLink)
                {
                    DropboxShares shares = CreateShareableLink(UploadPath, fileName);

                    if (shares != null)
                    {
                        result.URL = shares.URL;
                    }
                }
                else
                {
                    result.URL = GetDropboxURL(AccountInfo.Uid, UploadPath, fileName);
                }
            }

            return(result);
        }
Beispiel #4
0
        // 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);
        }
Beispiel #5
0
        // https://www.dropbox.com/developers/core/api#shares
        public DropboxShares CreateShareableLink(string path, bool short_url = true)
        {
            DropboxShares shares = null;

            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", short_url ? "true" : "false");

                string query = OAuthManager.GenerateQuery(url, args, HttpMethod.Post, AuthInfo);

                string response = SendPostRequest(query);

                if (!string.IsNullOrEmpty(response))
                {
                    shares = JsonConvert.DeserializeObject <DropboxShares>(response);
                }
            }

            return(shares);
        }