upload photos to specific folder
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?
Answers
-
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
0 -
[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.
0 -
http://localhost:5180/api/property/set-primary-photo/10/MyFolderName/o0hrifityrwe4avn5jqq
the bold text is the product id and 10 is property id
0 -
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
0 -
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
0 -
Great, sounds like you got it working!
If there are further questions on this topic, please let us know.
0