Matheus Miranda
Matheus Miranda

Reputation: 1805

How to send multiple images to cloudinary?

Follow code:

string[] files 
      = System.IO.Directory.GetFiles(@"C:\Users\Matheus Miranda\Pictures", "*.jpg");

foreach (var file in files)
{
    var uploadParams = new ImageUploadParams()
    {
        File = new FileDescription(file),
        PublicId = "my_folder/images",
        EagerAsync = true
    };

    var uploadResult = cloudinary.Upload(uploadParams);
}

It is not working, it is always recording the previous file.

I'm trying to save multiple images to cloudinary and nothing is success.

Only one image is saved. I use a libray Cloudinary.

Any solution ?

Upvotes: 0

Views: 297

Answers (2)

Matheus Miranda
Matheus Miranda

Reputation: 1805

I found the solution!

string[] files = 
    System.IO.Directory.GetFiles(@"C:\Users\Matheus Miranda\Pictures\teste", "*.jpg");

for (int i = 0; i < files.Length; i++)
{
    var uploadParams = new ImageUploadParams()
    {
        File = new FileDescription(files[i]),
        PublicId = $"my_folder/images/{System.IO.Path.GetFileName(files[i])}"
    };
    var uploadResult = cloudinary.Upload(uploadParams);
}

Upvotes: 0

Daniel Mendoza
Daniel Mendoza

Reputation: 497

When I tested it out, it works as expected; however, I would adjust a couple of things. The first thing is that you do not need the parameter eager_async as no eager transformation is being applied to the assets. An eager transformation lets you create a modified version of the original asynchronously after the asset has been uploaded. Secondly, if you wish to see the upload response, you can use property JsonObj and display it in the console. I have modified your sample here:

string[] files
= System.IO.Directory.GetFiles(@"C:\Users\Matheus Miranda\Pictures", "*.jpg");

foreach (var file in files)
{
    var uploadParams = new ImageUploadParams()
    {
        File = new FileDescription(file),
        UseFilename = true
    };

    var uploadResult = cloudinary.Upload(uploadParams);
    Console.WriteLine(uploadResult.JsonObj);
}

Upvotes: 1

Related Questions