Generating the url for UserImage
Moderators: alexandre, hugo, rmvanarkel
-
martin.rueegg
- Posts: 80
- Joined: Thu Aug 11, 2016 12:38 pm
- Location: Bristol, UK
- Contact:
Generating the url for UserImage
Hi there,
When accessing information about an image over the API, there is a property url available.
However, this property is not available in the UserImage object. How can the url be retreived within a script?
I do know, that it is composed by [network]/api/images/profile/[key]_[dimensions].jpeg. But I'd like to avid to replicate the coding.
Thanks,
Martin.
When accessing information about an image over the API, there is a property url available.
However, this property is not available in the UserImage object. How can the url be retreived within a script?
I do know, that it is composed by [network]/api/images/profile/[key]_[dimensions].jpeg. But I'd like to avid to replicate the coding.
Thanks,
Martin.
Cyclos v4.8.2 w/ Social license
Technical Manager, Bristol Pound CIC, Bristol, UK, http://bristolpound.org
Technical Manager, Bristol Pound CIC, Bristol, UK, http://bristolpound.org
-
rmvanarkel
- Posts: 270
- Joined: Tue Oct 05, 2010 1:14 pm
Re: Generating the url for UserImage
It is available, you can just use the key. It's available in the image parent:
http://documentation.cyclos.org/4.7/scr ... Image.html
http://documentation.cyclos.org/4.7/scr ... Image.html
-
martin.rueegg
- Posts: 80
- Joined: Thu Aug 11, 2016 12:38 pm
- Location: Bristol, UK
- Contact:
Re: Generating the url for UserImage
Hello rmvanarkel
thanks for your reply.
Which results in a usable URL: "https://[host]/cyclos/[Network]/api/images/profile/[key]_[width]x[height].[ext]".
But, to be honest, this is rubbish! first, the extension of the image does not reflect the original name. My best guess was using the second prat of ContentType. However, I am not sure, that will hold.
Just using the key itelf (without "_[width]x[height].[ext]", e.g."https://[host]/cyclos/[Network]/api/images/profile/[key]") results in an error:
Also, hardcoding the baseURL seems to be pointless.
Obviously, the API code in Cyclos has the functionality to produce the URL, as it is exposed through the API. Is there no way to access this function from within the Web Service script?
Thanks,
Martin.
thanks for your reply.
Yes, I have found this property. In fact, I am building the URL using the key:rmvanarkel wrote:It is available, you can just use the key. It's available in the image parent:
http://documentation.cyclos.org/4.7/scr ... Image.html
Code: Select all
private UserImage ui;
private String baseURL = "https://[host]/cyclos/[Network]/api/images/profile/";
// ... code filling the user
baseURL + ui.key+"_"+ui.width+"x"+ui.height+"."+ui.getContentType().substring(6)
But, to be honest, this is rubbish! first, the extension of the image does not reflect the original name. My best guess was using the second prat of ContentType. However, I am not sure, that will hold.
Just using the key itelf (without "_[width]x[height].[ext]", e.g."https://[host]/cyclos/[Network]/api/images/profile/[key]") results in an error:
Code: Select all
{"kind":"general","exceptionType":"java.lang.IllegalArgumentException"}Obviously, the API code in Cyclos has the functionality to produce the URL, as it is exposed through the API. Is there no way to access this function from within the Web Service script?
Thanks,
Martin.
Cyclos v4.8.2 w/ Social license
Technical Manager, Bristol Pound CIC, Bristol, UK, http://bristolpound.org
Technical Manager, Bristol Pound CIC, Bristol, UK, http://bristolpound.org
-
martin.rueegg
- Posts: 80
- Joined: Thu Aug 11, 2016 12:38 pm
- Location: Bristol, UK
- Contact:
Re: Generating the url for UserImage
Hi,
Any suggestion regarding the extension? (It cannot be extracted from the original name, as this does only match for png's ...)
Thanks,
Martin.
Any suggestion regarding the extension? (It cannot be extracted from the original name, as this does only match for png's ...)
Thanks,
Martin.
Cyclos v4.8.2 w/ Social license
Technical Manager, Bristol Pound CIC, Bristol, UK, http://bristolpound.org
Technical Manager, Bristol Pound CIC, Bristol, UK, http://bristolpound.org
-
martin.rueegg
- Posts: 80
- Joined: Thu Aug 11, 2016 12:38 pm
- Location: Bristol, UK
- Contact:
Re: Generating the url for UserImage
Hi
can I ask again if there is a function I could use to determine the url or at least the extension?f
Thank you,
Martin.
can I ask again if there is a function I could use to determine the url or at least the extension?f
Thank you,
Martin.
Cyclos v4.8.2 w/ Social license
Technical Manager, Bristol Pound CIC, Bristol, UK, http://bristolpound.org
Technical Manager, Bristol Pound CIC, Bristol, UK, http://bristolpound.org
-
erich.manser
- Posts: 24
- Joined: Tue Nov 08, 2022 10:40 am
Re: Generating the url for UserImage
Hi everybody,
was there ever found a solution for this problem? I would also like to create a rich-text within a custom operation presenting the user image. I didn't find an example in script documentation for cyclos 4.16.11.
was there ever found a solution for this problem? I would also like to create a rich-text within a custom operation presenting the user image. I didn't find an example in script documentation for cyclos 4.16.11.
-
jakob.schumann
- Posts: 63
- Joined: Thu Apr 23, 2020 5:37 pm
Re: Generating the url for UserImage
Hello Cyclos team!
This is also relevant for us.
It would be very good if there was a convenience function on the (User)Image class or at least the UserImageService to retrieve the complete URL (maybe only the path, without host & protocol) of an image, as the API would return it, e.g. in /{user}/images
Even better would be a method to retrieve the URL including all parameters to get the image in a specified size, like Cyclos uses in the frontend:
https://{host}/content/images/Z1TiVLlA4vEyOlekCjI2FJo8eBX5FEtFpyK7LiAwvooPfhv2wDbIghidExbkSjuy_960x621.jpeg?_k=1fe284a57d1b80be82ef38c36b3473d4f1d848d1&width=150&height=150
If there is no such method, what is the correct way (until such method is implemented) to construct this URL in a script? How should we get the extension in a save way, without parsing the contentType? What is the "_k" parameter in the above URL, it does not seem to be required?
Thanks in advance,
Jakob
This is also relevant for us.
It would be very good if there was a convenience function on the (User)Image class or at least the UserImageService to retrieve the complete URL (maybe only the path, without host & protocol) of an image, as the API would return it, e.g. in /{user}/images
Even better would be a method to retrieve the URL including all parameters to get the image in a specified size, like Cyclos uses in the frontend:
https://{host}/content/images/Z1TiVLlA4vEyOlekCjI2FJo8eBX5FEtFpyK7LiAwvooPfhv2wDbIghidExbkSjuy_960x621.jpeg?_k=1fe284a57d1b80be82ef38c36b3473d4f1d848d1&width=150&height=150
If there is no such method, what is the correct way (until such method is implemented) to construct this URL in a script? How should we get the extension in a save way, without parsing the contentType? What is the "_k" parameter in the above URL, it does not seem to be required?
Thanks in advance,
Jakob
Re: Generating the url for UserImage
The method Cyclos uses internally to generate the image URI is ServerImageHelper.imageURI.
The point is that it needs an ImageVO, not an actual Image.
See the example below:
The point is that it needs an ImageVO, not an actual Image.
See the example below:
Code: Select all
import org.cyclos.entities.users.User
import org.cyclos.impl.access.SessionData
import org.cyclos.impl.utils.conversion.ConversionHandler
import org.cyclos.model.system.images.ImageVO
import org.cyclos.server.utils.ServerImageHelper
ConversionHandler conversionHandler = binding.conversionHandler
SessionData sessionData = binding.sessionData
def c1 = conversionHandler.convert(User, 'loginName')
def image = conversionHandler.convert(ImageVO, c1.image)
def uri = ServerImageHelper.imageURI(image, sessionData.requestData, null)
println uri
Luis Fernando Planella Gonzalez
Cyclos development team
Cyclos development team
-
jakob.schumann
- Posts: 63
- Joined: Thu Apr 23, 2020 5:37 pm
Re: Generating the url for UserImage
Thanks Luis!
Ths worked like a charm in a custom export format, I hope this is still possible in other scripts where maybe no request is available (maybe cron job) and the sessionData is empty?
I have never seen the ConversionHandler before, this is a quite new feature? This will simplify a lot of scripts for us, where we need many VO's and get users via loginname etc.
Best regards,
Jakob
Ths worked like a charm in a custom export format, I hope this is still possible in other scripts where maybe no request is available (maybe cron job) and the sessionData is empty?
I have never seen the ConversionHandler before, this is a quite new feature? This will simplify a lot of scripts for us, where we need many VO's and get users via loginname etc.
Best regards,
Jakob