【问题标题】:C# .net windows forms; upload image with cloudinary through picturebox [duplicate]C# .net windows 窗体;通过图片框上传带有cloudinary的图像[重复]
【发布时间】: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) 时,它会抛出

this error

所以这可能是因为它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


【解决方案1】:

确保在调用 upload 之前运行以下行:

cloudinary = new Cloudinary(account);

【讨论】:

  • 我做了,之后我得到了这个错误:System.IO.FileNotFoundException: 'Could not load file or assembly'Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken =30ad4fe6b2a6aeed' 或其依赖项之一。系统找不到指定的文件。'
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-12-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多