c# - C# .net windows 窗体;通过picturebox上传带有cloudinary的图片
问题描述
首先,我是 .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'或其依赖项之一。该系统找不到指定的文件。'
我按照此处的步骤进行了修复,现在可以正常工作了。
解决方案
确保在调用之前运行以下行upload
:
cloudinary = new Cloudinary(account);
推荐阅读
- java - 如何不在 JFreeChart 中绘制时间序列的片段?
- react-native - 如何将两个参数传递给函数?(反应原生)
- javascript - Firebase - 重新身份验证后更新密码时出现问题
- tar - 远程从巨大的压缩包中提取文件
- python - 如何在 PyCharm Edu 中使用 tkinter 和 askopenfilename?
- java - 如何使用 Java 提取 XML 节点中的值列表
- azure-devops - 如何在托管代理上运行任意测试命令?
- c++ - 调用和重载模板函数
- c# - Noop for Fun
? - javascript - 将 Firebase 通知从 Web 应用扩展到移动应用