How to get an exception message from 'Cloudinary' API?

Comments

7 comments

  • Avatar
    Roee Ben Ari

    Hi,

    Would you mind sharing what error message that you caught so I can take a closer look?

    In general, if Cloudinary's server returned an error, it should be included as part of the response - 
    https://github.com/cloudinary/CloudinaryDotNet/blob/95768e6962b55ba7d6b4a44a89d6f70c05f3dd64/Shared/Actions/BaseResult.cs#L177

    You can fetch the error message by using result.Error.Message

     

     

    0
    Comment actions Permalink
  • Avatar
    MyeongJong Sim

    Hi,

    I found the exception cause that by timeout of API.
    However, the exception message is not provided in detail as below an image.

    Thanks

    0
    Comment actions Permalink
  • Avatar
    Roee Ben Ari

    Hi,

    Can you please share the code you use for CreateDownloadArchiveURL along with the full error stacktrace so I can better understand the issue?

    Thanks!

    0
    Comment actions Permalink
  • Avatar
    MyeongJong Sim

    Hi, 

    The exception error is occurred by "CreateZip" API.
    I guess it is timeout.

    ---- StackTrace-----------------------------------------------------------------

    / System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
    / System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
    / System.Threading.Tasks.Task.Wait()
    / Cloudinary.Test.Program.Main(String[] args)

     

    I share the test source.

    ---- Main source------------------------------------------------------------------------

    static void Main(string[] args)
    {
    var account = new Account("", "", "");
    var cloudinary = new CloudinaryDotNet.Cloudinary(account);
    //cloudinary.Api.Timeout = 60000;
    int maxFileCount = 110000;
    long maxFileSize = 523000000;

    Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-us");

    try
    {
    long totalFileSize = 0;
    int totalCount = 0;
    string nextCursor = string.Empty;
    var resources = new List<CloudinaryResourceDto>();

    do
    {

    var cloudinaryResultDto = SearchAPI(cloudinary, "metadata.ModelEnum=OS && metadata.ModelYearEnum=2019", nextCursor);

    nextCursor = cloudinaryResultDto.next_cursor;

    if (cloudinaryResultDto.resources != null && cloudinaryResultDto.resources.Any())
    {
    cloudinaryResultDto.resources.ForEach(r =>
    {
    if ((totalFileSize + r.bytes) < maxFileSize && totalCount < maxFileCount)
    {
    resources.Add(r);
    totalFileSize += r.bytes;

    totalCount++;
    }
    else
    {
    nextCursor = string.Empty;
    }
    });
    }

    Console.WriteLine($"Current count: {totalCount} / Total file size: {AdjustFileSize(totalFileSize)}");
    }
    while (string.IsNullOrEmpty(nextCursor) == false && totalFileSize < maxFileSize && totalCount < maxFileCount);

    var selectedImages = resources
    .Where(r => r.resource_type == "image")?
    .ToList();

    var selectedVideos = resources
    .Where(r => r.resource_type == "video")?
    .ToList();

    var selectedRaws = resources
    .Where(r => r.resource_type == "raw")?
    .ToList();

    var currentUTCDateTime = DateTime.UtcNow;
    var createArchivePublicIds = new List<string>();

    Console.WriteLine($"Total count: {resources.Count}");
    Console.WriteLine($"Total size: {AdjustFileSize(resources.Sum(x => x.bytes))}");
    if (resources.Count > 0 && true)
    {
    Task<string> compressedResourceFile = CreateComplexZip(cloudinary, resources.Select(x => $"{x.resource_type}/{x.type}/{x.public_id}").ToList(), "auto", currentUTCDateTime);
    compressedResourceFile.Wait();
    createArchivePublicIds.Add(compressedResourceFile.Result);
    }

    Console.WriteLine($"Image file size: {AdjustFileSize(selectedImages.Sum(x => x.bytes))}");
    if (selectedImages.Count > 0 && false)
    {
    createArchivePublicIds.Add(CreateZip(cloudinary, selectedImages.Select(x => x.public_id).ToList(), "image", currentUTCDateTime));
    }

    Console.WriteLine($"Video file size: {AdjustFileSize(selectedVideos.Sum(x => x.bytes))}");
    if (selectedVideos.Count > 0 && false)
    {
    createArchivePublicIds.Add(CreateZip(cloudinary, selectedVideos.Select(x => x.public_id).ToList(), "video", currentUTCDateTime));
    }

    Console.WriteLine($"Raw file size: {AdjustFileSize(selectedRaws.Sum(x => x.bytes))}");
    if (selectedRaws.Count > 0 && false)
    {
    createArchivePublicIds.Add(CreateZip(cloudinary, selectedRaws.Select(x => x.public_id).ToList(), "raw", currentUTCDateTime));
    }

    Console.WriteLine(JsonConvert.SerializeObject(createArchivePublicIds));

    Console.WriteLine($"Start CreateZip API : {DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:ffff")}");
    string downloadArchiveUrl = CreateDownloadArchiveUrl(cloudinary, createArchivePublicIds, currentUTCDateTime);
    Console.WriteLine($"Finish CreateZip API : {DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:ffff")}");

    Console.WriteLine(downloadArchiveUrl);
    }
    catch (Exception ex)
    {
    Console.WriteLine($"Exception : {DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:ffff")}");
    Console.WriteLine(ex.Message);
    }
    finally
    {
    Console.ReadKey();
    }

     

    ---- CreatZip source------------------------------------------------------------------------

    static string CreateZip(CloudinaryDotNet.Cloudinary cloudinary, List<string> selectedPublicIds, string resourceTypeEnum, DateTime currentDateTime)
    {
    string orderId = $"{currentDateTime.ToString("yyyyMMddHHmmssffff")}";

    var createZipParams = new ArchiveParams();

    createZipParams.ResourceType(resourceTypeEnum);
    createZipParams.PublicIds(selectedPublicIds);
    createZipParams.TargetPublicId($"Test_{orderId}_{resourceTypeEnum}.zip");
    //createZipParams.ExpiresAt(ConvertUnixTime(currentDateTime.AddHours(2)));

    Console.WriteLine($"Start CreateZip API : {DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:ffff")}");
    var createZipResult = cloudinary.CreateZip(createZipParams);
    Console.WriteLine($"Finish CreateZip API : {DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:ffff")}");

    Console.WriteLine(JsonConvert.SerializeObject(createZipResult.JsonObj));

    return createZipResult.PublicId;
    }

    0
    Comment actions Permalink
  • Avatar
    Shirly Manor

    Hi,

    In order to provide better feedback, can you please open a ticket at support@cloudinary.com with your cloud name?

    Also, can you try running this sample code and let us know if that works?

    var archiveParams = new ArchiveParams().PublicIds(new List<string>(){"one of your public id", "sample"});

    stringurl = cloudinary.DownloadArchiveUrl(archiveParams);

    Console.WriteLine(url);

     

    0
    Comment actions Permalink
  • Avatar
    MyeongJong Sim

    Hi,

    Your sample code works fine well.

    ex) If the file size limit is exceeded or it takes a long time, not receiving the detailed error message.

    0
    Comment actions Permalink
  • Avatar
    Shirly Manor

    Yes, that is correct, this function returned only the URL. If you want to get the result you might want to use the createZip function.

     

    ```

    var archiveParams = new ArchiveParams().PublicIds(new List<string>(){"dog", "sample"});vararchiveResult = cloudinary.CreateZip(archiveParams);Console.WriteLine(archiveResult.JsonObj.ToString());

    ```
    0
    Comment actions Permalink

Please sign in to leave a comment.