【发布时间】:2020-12-08 16:48:59
【问题描述】:
首先,我是 .net/C# 的新手
我希望用户通过图片框选择一张图片,图片应该直接上传到cloudinary。
public static Cloudinary cloudinary;
public const string CLOUD_NAME = "XXXXXX";
public const string API_KEY = "XXXXXXX";
public const string API_SECRET = "XXXXXX";
string imagePath = "";
static void cloudinaryAccount(string[] args)
{
Account account = new Account(CLOUD_NAME, API_KEY, API_SECRET);
cloudinary = new Cloudinary(account);
}
private void pictureBox1_Click(object sender, EventArgs e)
{
OpenFileDialog dialog = new OpenFileDialog();
dialog.Filter = "All files(*.*)|*.*";
if (dialog.ShowDialog() == DialogResult.OK)
{
imagePath = dialog.FileName.ToString();
pictureBox1.ImageLocation = imagePath;
}
uploadImage(imagePath); // pass the path of the image to the uploadImage() function.
}
public static void uploadImage(string imagePath)
{
var UploadParams = new ImageUploadParams()
{
File = new FileDescription(imagePath)
};
var uploadResult = cloudinary.Upload(UploadParams);
}
但是当涉及到 cloudinary.Upload(UploadParams) 时,它会抛出
所以这可能是因为它cloudinary 为空。
所以如果我搬家
Account account = new Account(CLOUD_NAME, API_KEY, API_SECRET);
cloudinary = new Cloudinary(account);
进入uploadImage(string imagePath)函数,我得到以下错误:
System.IO.FileNotFoundException: '无法加载文件或程序集'Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' 或其依赖项之一。系统找不到指定的文件。'
我按照here 的步骤进行了修复,现在可以使用了。
【问题讨论】:
-
使用你的调试器。
标签: c# .net winforms picturebox cloudinary