Home > Enterprise >  Upload Image to Dropbox with URL
Upload Image to Dropbox with URL

Time:12-28

DropboxClient dbx =  new DropboxClient("my_Key");

var folder = "/Apps/Images";

var file = $"fileName.jpg";

var fileToUpload = @"C:\Users\LENOVO\Test\Test\test.jpg";

using (var mem = new MemoryStream(File.ReadAllBytes(fileToUpload)))
{

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

     Console.WriteLine("Saved {0}/{1} rev {2}", folder, file, updated.Rev);
 }

i want to upload Image to Dropbox. This code is worked but i want fileToUpload to be is a web URL because images is a Web Server. i know i can download every Images step by step. But this is a loss of performance. If i write a WebUrl in the fileToUpload. i see the exception. For Example: fileToUpload = "https:\upload.wikimedia.org\wikipedia\commons\5\51\Small_Red_Rose.JPG"

The Exception:

C:\Users\LENOVO****\bin\Debug\net6.0\https:\upload.wikimedia.org\wikipedia\commons\5\51\Small_Red_Rose.JPG

*** - is a local folder name

i want to upload image to dropbox from Web

CodePudding user response:

The UploadAsync method requires that you supply the data of the file to upload directly, as you are doing in your example by retrieving the file data from the local filesystem using File.ReadAllBytes.

If you want to upload a file to Dropbox directly from a URL without downloading it to your local filesystem first, you should instead use the SaveUrlAsync method.

  • Related