Hello.
I am trying to upload an image file into my dropbox account with the dropbox api. The image is being uploaded using this code, but it's a corrupt image.
Here is my code:
public async Task UploadToDropbox()
{
using (var dbx = new DropboxClient(dbToken))
{
string srcFilePath = @~\useruploads\;
string srcFileName = "image1.png";
string srcFile = srcFilePath + srcFileName;
string targetFolder = "/uploads";
string targetFileName = "userupload_" + DateTime.Now.ToString("yymmssfff") + ".png";
//byte[] readContent = Encoding.UTF8.GetBytes(srcFile); //uploading corrupt file
//byte[] readContent = UTF8Encoding.UTF8.GetBytes(srcFile); //uploading corrupt file
//var readContent = System.IO.File.ReadAllBytes(srcFile); //uploading nothing
//byte[] readContent = System.IO.File.ReadAllBytes(srcFile); //uploading nothing
using (var mem = new MemoryStream(readContent))
{
var updated = await dbx.Files.UploadAsync(
targetFolder + "/" + targetFileName,
WriteMode.Overwrite.Instance,
body: mem);
}
}
}
Thank you for any help.