Cloudinary generated hidden input value -
i'm using node.js generate direct upload file tag cloudinary
cloudinary.uploader.image_upload_tag('coverimage', {html: {'class': 'cloudinary-coverimage', format: 'jpg'}})
after uploading, hidden input
tag auto generated @ end of form:
<input type="hidden" name="coverimage" value="image/upload/v1431361091/bns8et8ksrx3km5esdpj.jpg#d36285fd9bcccd5a2034b22ebf69d867fcee0bbc">
i realize input value not public id said in docs, when store in db, not generate proper image
cloudinary.image(abc.coverimage)
how can image's exact public id in hidden input value?
tl;dr
the format of hidden input tag's value {resource_type}/{type}/v{version}/{public_id}.{format}#{signature}
. need public_id, in example bns8et8ksrx3km5esdpj
.
details
the value of hidden field includes resource type, version, public id , signature of uploaded image. public_id
last part of uri before hash (#).
refer sample code, taken node.js controller code, example of handling upload results (to match example above, image_id
below should replaced name designated field, i.e. coverimage
):
var photo = schema.models.photo; var photo = new photo(req.body); var image = new cloudinary.preloadedfile(req.body.image_id); // check image resolved image_id valid if (image.is_valid()){ photo.image = image.tojson(); console.dir(photo.image) } photo.save().then(function(photo){ console.log('** photo saved') })
brower side
if need public_id
of image following direct upload on browser side, should listen "cloudinarydone"
event:
$("body").on( "cloudinarydone", function(e, data) { console.log(data.result.public_id); });
Comments
Post a Comment