如何解决C#.net Windows窗体;通过图片框上传包含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_SECRET);
cloudinary = new Cloudinary(account);
进入uploadImage(string imagePath)
函数,出现以下错误:
System.IO.FileNotFoundException:'无法加载文件或程序集'Newtonsoft.Json,版本= 12.0.0.0,Culture =中性,PublicKeyToken = 30ad4fe6b2a6aeed'或其依赖项之一。系统找不到指定的文件。'
我按照here的步骤进行了修复,现在可以正常工作了。
解决方法
确保在调用upload
之前运行以下行:
cloudinary = new Cloudinary(account);
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。