Beispiel #1
0
        /// <summary>Uploads file in existing folder in Dropbox.</summary>
        /// <param name="folder">
        /// Path to the folder. Always begin with "/" - the root Dropbox folder. Example: "/Contests/Active"
        /// </param>
        /// <param name="file">Name of the file with the filename extension. Example: "Abstract5567.jpg"</param>
        /// <param name="content">A generic view of a sequence of bytes. (Stream)</param>
        /// <returns>On success returns shared link of the file, otherwise null.</returns>
        public static async Task <string> Upload(string folder, string file, Stream content)
        {
            string sharedLink = null;

            using (var dbx = new DropboxClient(DropboxAppAccessToken))
            {
                using (var mem = new MemoryStream())
                {
                    content.Position = 0;
                    content.CopyTo(mem);

                    mem.Position = 0;

                    try
                    {
                        var uploaded = await dbx.Files.UploadAsync(
                            folder + "/" + file,
                            WriteMode.Overwrite.Instance,
                            body : mem);

                        var sharedLinkArg = new Dropbox.Api.Sharing.CreateSharedLinkArg(folder + "/" + file);
                        var link          = await dbx.Sharing.CreateSharedLinkAsync(sharedLinkArg);

                        sharedLink = link.Url;
                    }
                    catch (Exception)
                    { }
                }
            }

            return(sharedLink);
        }
        /// <summary>Uploads file in existing folder in Dropbox.</summary>
        /// <param name="folder">
        /// Path to the folder. Always begin with "/" - the root Dropbox folder. Example: "/Contests/Active"
        /// </param>
        /// <param name="file">Name of the file with the filename extension. Example: "Abstract5567.jpg"</param>
        /// <param name="content">A generic view of a sequence of bytes. (Stream)</param>
        /// <returns>On success returns shared link of the file, otherwise null.</returns>
        public static async Task<string> Upload(string folder, string file, Stream content)
        {
            string sharedLink = null;

            using (var dbx = new DropboxClient(DropboxAppAccessToken))
            {
                using (var mem = new MemoryStream())
                {
                    content.Position = 0;
                    content.CopyTo(mem);

                    mem.Position = 0;

                    try
                    {
                        var uploaded = await dbx.Files.UploadAsync(
                        folder + "/" + file,
                        WriteMode.Overwrite.Instance,
                        body: mem);

                        var sharedLinkArg = new Dropbox.Api.Sharing.CreateSharedLinkArg(folder + "/" + file);
                        var link = await dbx.Sharing.CreateSharedLinkAsync(sharedLinkArg);

                        sharedLink = link.Url;
                    }
                    catch (Exception)
                    { }
                }
            }

            return sharedLink;
        }