public static string GetDropboxURL(long userID, string uploadPath, string fileName)
        {
            if (!string.IsNullOrEmpty(uploadPath) && uploadPath.StartsWith("Public/", StringComparison.InvariantCultureIgnoreCase) && !string.IsNullOrEmpty(fileName))
            {
                return(ZAppHelper.CombineURL(URLDownload, userID.ToString(), uploadPath.Substring(7), HttpUtility.UrlPathEncode(fileName)));
            }

            return("Upload path is private. Use \"Public\" folder to get public URL.");
        }
        /// <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);
        }
        /// <summary>Retrieves file and folder metadata.</summary>
        /// <param name="path">The path to the file or folder.</param>
        /// <returns>
        /// The metadata for the file or folder at the given <path>.
        /// If <path> represents a folder and the list parameter is true, the metadata will also include a listing of metadata for the folder's contents.
        /// </returns>
        public DropboxDirectoryInfo GetFilesList(string path)
        {
            DropboxDirectoryInfo directoryInfo = null;

            if (OAuthInfo.CheckOAuth(AuthInfo))
            {
                string url = OAuthManager.GenerateQuery(ZAppHelper.CombineURL(URLMetaData, path), null, HttpMethod.Get, AuthInfo);

                string response = SendGetRequest(url);

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

            return(directoryInfo);
        }
        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);
        }
        public override UploadResult Upload(Stream stream, string fileName)
        {
            UploadResult ur = new UploadResult();

            Dictionary <string, string> args = new Dictionary <string, string>();

            args.Add("api_key", API_Key);
            args.Add("auth_token", this.Auth.Token);

            if (!string.IsNullOrEmpty(Settings.Title))
            {
                args.Add("title", Settings.Title);
            }
            if (!string.IsNullOrEmpty(Settings.Description))
            {
                args.Add("description", Settings.Description);
            }
            if (!string.IsNullOrEmpty(Settings.Tags))
            {
                args.Add("tags", Settings.Tags);
            }
            if (!string.IsNullOrEmpty(Settings.IsPublic))
            {
                args.Add("is_public", Settings.IsPublic);
            }
            if (!string.IsNullOrEmpty(Settings.IsFriend))
            {
                args.Add("is_friend", Settings.IsFriend);
            }
            if (!string.IsNullOrEmpty(Settings.IsFamily))
            {
                args.Add("is_family", Settings.IsFamily);
            }
            if (!string.IsNullOrEmpty(Settings.SafetyLevel))
            {
                args.Add("safety_level", Settings.SafetyLevel);
            }
            if (!string.IsNullOrEmpty(Settings.ContentType))
            {
                args.Add("content_type", Settings.ContentType);
            }
            if (!string.IsNullOrEmpty(Settings.Hidden))
            {
                args.Add("hidden", Settings.Hidden);
            }

            args.Add("api_sig", GetAPISig(args));

            ur.Source = UploadData(stream, API_Upload_URL, fileName, "photo", args);

            if (!string.IsNullOrEmpty(ur.Source))
            {
                XElement xele = ParseResponse(ur.Source, "photoid");

                if (null != xele)
                {
                    string photoid = xele.Value;
                    string url     = ZAppHelper.CombineURL(GetPhotosLink(), photoid);
                    ur.URL = ZAppHelper.CombineURL(url, "sizes/o");
                }
            }

            return(ur);
        }
 public string GetPhotosLink(string userID)
 {
     return(ZAppHelper.CombineURL("http://www.flickr.com/photos", userID));
 }