upload photos to specific folder

rwahdan
rwahdan Member Posts: 51

Hi,

I tried to upload a photo to specific folder and it works fine but when trying to access the photo with the public id that has a folder name included as photo public id I get error. I tried that in postman so it considers the string (photo_public_id) is equal to ("myfolder/hjgshdgjdg) it will conside that as a path not as a public id. Is there a way to deal with that?

Tagged:

Answers

  • Tamara
    Tamara Member, Cloudinary Staff Posts: 123

    Hi @rwahdan

    Upon uploading a new asset, the response includes the complete URL. As you rightly pointed out, the folder is integral to the public ID.

    Could you provide an example? If you prefer not to share it publicly here, feel free to initiate a new private ticket for further assistance.

    Best,

    Tamara

  • rwahdan
    rwahdan Member Posts: 51

    [HttpPost("set-primary-photo/{propId}/{photoPublicId}")]

            [Authorize]

            public async Task<IActionResult> SetPrimaryPhoto(int propId, string photoPublicId)

            {

                var userId = GetUserId();

                var property = await uow.PropertyRepository.GetPropertyByIdAsync(propId);

               

                if (property == null)

                    return BadRequest("No such property or photo exists");


                if (property.PostedBy != userId)

                    return BadRequest("You are not authorized to change the primary photo!");


                var photo = property.Photos.FirstOrDefault(p => p.PublicId == photoPublicId);


                if (photo == null)

                    return BadRequest("No such property or photo exists");


                if (photo.IsPrimary)

                    return BadRequest("photo is already a primary photo!");


                var currentPrimary = property.Photos.FirstOrDefault(p => p.IsPrimary);


                if (currentPrimary != null) currentPrimary.IsPrimary = false;


                photo.IsPrimary = true;


                if (await uow.SaveAsync()) return NoContent();


                return BadRequest("Some error has occured, failed to set the primary photo!");

            }


    when I run this to postman with the following code:

    I get error can't access page.

  • rwahdan
    rwahdan Member Posts: 51
    edited March 3

    http://localhost:5180/api/property/set-primary-photo/10/MyFolderName/o0hrifityrwe4avn5jqq

    the bold text is the product id and 10 is property id

  • Tamara
    Tamara Member, Cloudinary Staff Posts: 123

    Hi @rwahdan, can you please try encoding the folder \ with %2F? and this might be causing the problem.

    If not - please share your postman collection or share how it specifically relates to a Cloudinary method.

    Thanks

  • rwahdan
    rwahdan Member Posts: 51
    edited March 3

    now i get no such photo exists

    the postman:

    http://localhost:5180/api/property/set-primary-photo/10/MarinaSquarePark%2Fxrswwucm6bhujj9mxmtd

    but if I save the image without folder it is ok (after i comment the folder part when saving the image:

    http://localhost:5180/api/property/set-primary-photo/10/xrswwucm6bhujj9mxmtd

  • Tamara
    Tamara Member, Cloudinary Staff Posts: 123

    Hi @rwahdan, I don't see how is this a Cloudinary issue and I need more information to help. Can you please describe your workflow in more detail?

    -Tamara

  • rwahdan
    rwahdan Member Posts: 51
    edited March 6

    I editted the code so that all parts are taken to one string. this way it is working...


    http://localhost:5180/api/property/set-primary-photo/10/MarinaSquareParkFxrswwucm6bhujj9mxmtd

  • Cloudinary_John_H
    Cloudinary_John_H Cloudinary Staff Posts: 50

    Great, sounds like you got it working!

    If there are further questions on this topic, please let us know.