Beispiel #1
0
        public UploadResult UploadFile(Stream stream, string path, string filename, bool createShareableLink = false, bool useDirectLink = false)
        {
            if (stream.Length > 150000000)
            {
                Errors.Add("There's a 150MB limit to uploads through the API.");
                return(null);
            }

            string json = JsonConvert.SerializeObject(new
            {
                path       = VerifyPath(path, filename),
                mode       = "overwrite",
                autorename = false,
                mute       = true
            });

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

            args.Add("arg", json);

            string response = SendRequest(HttpMethod.POST, URLUpload, stream, ContentTypeOctetStream, args, GetAuthHeaders());

            UploadResult ur = new UploadResult(response);

            if (!string.IsNullOrEmpty(ur.Response))
            {
                DropboxMetadata metadata = JsonConvert.DeserializeObject <DropboxMetadata>(ur.Response);

                if (metadata != null)
                {
                    if (createShareableLink)
                    {
                        AllowReportProgress = false;

                        ur.URL = CreateShareableLink(metadata.path_display, useDirectLink);
                    }
                    else
                    {
                        ur.IsURLExpected = false;
                    }
                }
            }

            return(ur);
        }
Beispiel #2
0
        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);
        }
Beispiel #3
0
        public DropboxMetadata Delete(string path)
        {
            DropboxMetadata metadata = null;

            if (!string.IsNullOrEmpty(path) && OAuth2Info.CheckOAuth(AuthInfo))
            {
                string json = JsonConvert.SerializeObject(new
                {
                    path = VerifyPath(path)
                });

                string response = SendRequest(HttpMethod.POST, URLDelete, json, ContentTypeJSON, null, GetAuthHeaders());

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

            return(metadata);
        }
Beispiel #4
0
        public DropboxMetadata CreateFolder(string path)
        {
            DropboxMetadata metadata = null;

            if (!string.IsNullOrEmpty(path) && OAuth2Info.CheckOAuth(AuthInfo))
            {
                string json = JsonConvert.SerializeObject(new
                {
                    path = VerifyPath(path)
                });

                string response = SendRequestJSON(URLCreateFolder, json, GetAuthHeaders());

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

            return(metadata);
        }
Beispiel #5
0
        public DropboxMetadata Move(string fromPath, string toPath)
        {
            DropboxMetadata metadata = null;

            if (!string.IsNullOrEmpty(fromPath) && !string.IsNullOrEmpty(toPath) && OAuth2Info.CheckOAuth(AuthInfo))
            {
                string json = JsonConvert.SerializeObject(new
                {
                    from_path = VerifyPath(fromPath),
                    to_path   = VerifyPath(toPath)
                });

                string response = SendRequestJSON(URLMove, json, GetAuthHeaders());

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

            return(metadata);
        }
Beispiel #6
0
        public DropboxMetadata Copy(string fromPath, string toPath)
        {
            DropboxMetadata metadata = null;

            if (!string.IsNullOrEmpty(fromPath) && !string.IsNullOrEmpty(toPath) && OAuth2Info.CheckOAuth(AuthInfo))
            {
                string json = JsonConvert.SerializeObject(new
                {
                    from_path = VerifyPath(fromPath),
                    to_path   = VerifyPath(toPath)
                });

                string response = SendRequest(HttpMethod.POST, URLCopy, json, RequestHelpers.ContentTypeJSON, null, GetAuthHeaders());

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

            return(metadata);
        }
Beispiel #7
0
        public DropboxMetadata GetMetadata(string path)
        {
            DropboxMetadata metadata = null;

            if (path != null && OAuth2Info.CheckOAuth(AuthInfo))
            {
                string json = JsonConvert.SerializeObject(new
                {
                    path = VerifyPath(path),
                    include_media_info = false,
                    include_deleted    = false,
                    include_has_explicit_shared_members = false
                });

                string response = SendRequest(HttpMethod.POST, URLGetMetadata, json, ContentTypeJSON, null, GetAuthHeaders());

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

            return(metadata);
        }
Beispiel #8
0
        public bool IsExists(string path)
        {
            DropboxMetadata metadata = GetMetadata(path);

            return(metadata != null && !metadata.tag.Equals("deleted", StringComparison.InvariantCultureIgnoreCase));
        }