First of all, I'm new to .net/C#
I want the user to pick an image through a picturebox and the image should upload directly to 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);
}
But when it comes to the cloudinary.Upload(UploadParams)
it throws
So it's probably because it cloudinary
is null.
So if I move
Account account = new Account(CLOUD_NAME, API_KEY, API_SECRET);
cloudinary = new Cloudinary(account);
into the uploadImage(string imagePath)
function, I get the following error:
System.IO.FileNotFoundException: 'Could not load file or assembly 'Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The system cannot find the file specified.'
I followed the steps here and fixed it, it's working now.