我的图片框图片未使用 Api 保存到 Dropbox 文件夹
My picturebox image is not saving to dropbox folder using Api
这是我的代码:
static string token = "<REDACTED>";
async Task Upload()
{
using (var dbx = new DropboxClient(token))
{
//C: \Users\home\Downloads\abba.JPG
//string file = @"C:\Users\home\Downloads\FazalNEwTEst.JPG";
string folder = "";
string filename = "EziTest-2-jun-2020.JPG";
string url = pictureBox1.Image.ToString();
ImageConverter converter = new ImageConverter();
byte[] bytes = (byte[])converter.ConvertTo(pictureBox1.Image, typeof(byte[]));
string base64String = Convert.ToBase64String(bytes, 0, bytes.Length);
var mem = new MemoryStream(File.ReadAllBytes(base64String));
//using ()
//{
var updated = dbx.Files.UploadAsync(folder + "/" + filename, WriteMode.Overwrite.Instance, body: mem);
updated.Wait();
var tx = dbx.Sharing.CreateSharedLinkWithSettingsAsync(folder + "/" + filename);
tx.Wait();
url = tx.Result.Url;
//}
//Console.Write(url)
}
}
按钮点击代码为:
private void button1_Click(object sender, EventArgs e)
{
var awt = Task.Run((Func<Task>)this.Upload);
awt.Wait();
}
当我点击图片时,picturebox 图像应该使用 Api 标记保存到 dropbox 文件夹中。但实际上它给我的错误是
DirectoryNotFoundException: Could not find a part of the path 'E:\visual studio projects\Windows form Application tutorials\Dropbox Api Demo\Dropbox Api Demo\bin\Debug\iVBORw0KGgoAAAANSUhEUgAAAGQAAABkCAYAAABw4pVUAAAABGdBTUEAALGPC\xhBQAAA1FJREFUeF7t2ttLVFEcxXH\qKjogmWWRplaSEkWQUIPQkkQShTZlbySZqKZEZTVQzcIIgiKUMtSpEC6IFbmZRzHchwVEkd27OEneNyBOM1h1tlnfWE9neM87A8y4xlTGGOMMWZx11rvKs79yXEvn775YEu72tncw7kwfbYrBtE\uKqxj3Nh+mwJAjSCgI0gYCMI2AgCNoKAjSBgIwjYCAI2goAtLhA+y3JvcT3L4tyfHPfylVbeUP0\RxRzJ322+ozluJePIO5GELAIAhZBwCIIWAQBiyBgEQQsgoBFELAIAhZBwCIIWAQBiyBgEQQsz4J0dHarx0+fJ3RDIwF59eTlWZDikrNq9aashO7FqzZ59eRFkEUjyH+UaJC1adlqYHBIXj15eRbkZFm52pKVH9f04S8FOVdeK6+c3DwLEm+h8V9qY8YeB8b69FyIN3Sd70Au1zQ4MPQqaxvlavLzFUggOKY2bN3twNC\LWOhcbkj+fkK5FLVVQeGXn3TLbmKkW9AAqPB2HvFYoy0HXtVeDIid2DkG5ALFXUODL2mm61yFSdfgAwOB9S69BwHRmpmnpoIT8odOPkCpOJKowNDr6a+Wa5iZT1IZGpapW7Pc2Do35bRYEjuwMp6kDv3Hzkw9E6fr5KreFkNMj8\r3LyCw2Qj72f5Q68rAZ5+brDwCgoPCZXMbMa5MjRUgNEfxGFnLUgX\v6DQz9mGRqekbuwMxakOq66wYI8pv5QlaCRKNRlZl7wADp7OqRO3CzEqTtzXsDIyOnIPapCz0rQc5crDZA9LMsL2QdyNxcNPY17VKQ9rddcgd21oG86gYOhHJ7Ozs3IHdtaB
尝试换行
byte[] bytes = (byte[])converter.ConvertTo(pictureBox1.Image, typeof(byte[]));
string base64String = Convert.ToBase64String(bytes, 0, bytes.Length);
var mem = new MemoryStream(File.ReadAllBytes(base64String));
至
byte[] bytes = (byte[])converter.ConvertTo(pictureBox1.Image, typeof(byte[]));
var mem = new MemoryStream(bytes);
您不需要将 byte
数组转换为 base64 string
。是代码 File.ReadAllBytes(base64String)
试图从磁盘
中读取具有乱码名称的文件
这是我的代码:
static string token = "<REDACTED>";
async Task Upload()
{
using (var dbx = new DropboxClient(token))
{
//C: \Users\home\Downloads\abba.JPG
//string file = @"C:\Users\home\Downloads\FazalNEwTEst.JPG";
string folder = "";
string filename = "EziTest-2-jun-2020.JPG";
string url = pictureBox1.Image.ToString();
ImageConverter converter = new ImageConverter();
byte[] bytes = (byte[])converter.ConvertTo(pictureBox1.Image, typeof(byte[]));
string base64String = Convert.ToBase64String(bytes, 0, bytes.Length);
var mem = new MemoryStream(File.ReadAllBytes(base64String));
//using ()
//{
var updated = dbx.Files.UploadAsync(folder + "/" + filename, WriteMode.Overwrite.Instance, body: mem);
updated.Wait();
var tx = dbx.Sharing.CreateSharedLinkWithSettingsAsync(folder + "/" + filename);
tx.Wait();
url = tx.Result.Url;
//}
//Console.Write(url)
}
}
按钮点击代码为:
private void button1_Click(object sender, EventArgs e)
{
var awt = Task.Run((Func<Task>)this.Upload);
awt.Wait();
}
当我点击图片时,picturebox 图像应该使用 Api 标记保存到 dropbox 文件夹中。但实际上它给我的错误是
DirectoryNotFoundException: Could not find a part of the path 'E:\visual studio projects\Windows form Application tutorials\Dropbox Api Demo\Dropbox Api Demo\bin\Debug\iVBORw0KGgoAAAANSUhEUgAAAGQAAABkCAYAAABw4pVUAAAABGdBTUEAALGPC\xhBQAAA1FJREFUeF7t2ttLVFEcxXH\qKjogmWWRplaSEkWQUIPQkkQShTZlbySZqKZEZTVQzcIIgiKUMtSpEC6IFbmZRzHchwVEkd27OEneNyBOM1h1tlnfWE9neM87A8y4xlTGGOMMWZx11rvKs79yXEvn775YEu72tncw7kwfbYrBtE\uKqxj3Nh+mwJAjSCgI0gYCMI2AgCNoKAjSBgIwjYCAI2goAtLhA+y3JvcT3L4tyfHPfylVbeUP0\RxRzJ322+ozluJePIO5GELAIAhZBwCIIWAQBiyBgEQQsgoBFELAIAhZBwCIIWAQBiyBgEQQsz4J0dHarx0+fJ3RDIwF59eTlWZDikrNq9aashO7FqzZ59eRFkEUjyH+UaJC1adlqYHBIXj15eRbkZFm52pKVH9f04S8FOVdeK6+c3DwLEm+h8V9qY8YeB8b69FyIN3Sd70Au1zQ4MPQqaxvlavLzFUggOKY2bN3twNC\LWOhcbkj+fkK5FLVVQeGXn3TLbmKkW9AAqPB2HvFYoy0HXtVeDIid2DkG5ALFXUODL2mm61yFSdfgAwOB9S69BwHRmpmnpoIT8odOPkCpOJKowNDr6a+Wa5iZT1IZGpapW7Pc2Do35bRYEjuwMp6kDv3Hzkw9E6fr5KreFkNMj8\r3LyCw2Qj72f5Q68rAZ5+brDwCgoPCZXMbMa5MjRUgNEfxGFnLUgX\v6DQz9mGRqekbuwMxakOq66wYI8pv5QlaCRKNRlZl7wADp7OqRO3CzEqTtzXsDIyOnIPapCz0rQc5crDZA9LMsL2QdyNxcNPY17VKQ9rddcgd21oG86gYOhHJ7Ozs3IHdtaB
尝试换行
byte[] bytes = (byte[])converter.ConvertTo(pictureBox1.Image, typeof(byte[]));
string base64String = Convert.ToBase64String(bytes, 0, bytes.Length);
var mem = new MemoryStream(File.ReadAllBytes(base64String));
至
byte[] bytes = (byte[])converter.ConvertTo(pictureBox1.Image, typeof(byte[]));
var mem = new MemoryStream(bytes);
您不需要将 byte
数组转换为 base64 string
。是代码 File.ReadAllBytes(base64String)
试图从磁盘