Programmatically downloading image from CQ5 - aem

I am trying to programmatically download a image from CQ5.I have made a link which when clicked should download a image.To do this I have made a ajax call to a servlet ,for whenever user clicks on the image,we should get a pop of open and save dialog.
This is the code I have written in servlet to download the image.
**response.setContentType("image/png");
response.setHeader("Content-Disposition", "attachment; filename=icon" + ".png");
URL url = new URL("http://somehost:portnmuber/content/dam/image.jpg");
URLConnection connection = url.openConnection();
InputStream stream = connection.getInputStream();**
I am continuously getting 401 error.
Is there some another way that I can do this.
Thanks,in advance.

Firstly, have a look at the download component in the foundation libs:
/libs/foundation/components/download/download.jsp
Secondly, if you don't have a session open with CQ5, it will by default give you a 401 error. I am assuming you are in a generated container for CQ5, or are you just randomly accessing from another domain?
Note that even for anonymous access, CQ will still establish an anonymous session, and give you a login token. Anonymous is effectively still authenticated, just without the requirement of a username and password.

You are gettin 401 error because anonymous user permissions for the DAM are not set.
At first, you should grant access permissions for 'anonymous' users for node '/content/dam'.
You can do it from the page: "http://somehost:portnuber/useradmin" . Doble click on user 'anonymous' and go to the tab 'permissions' (on the window right). Check read permissions for 'dam' node.
Secondly, go to the system console, components tab (http://somehost:portnmuber/system/console/components) and find org.apache.sling.engine.impl.auth.SlingAuthenticator component. Click to 'configure' button. In the component configuration check 'Allow Anonymous Access' and press 'Save'.
Should work.

CQ5 uses sessions so downloading from a path requires a username/password on the author instance, for example curl -u username:password http://someserver.com:4502/etc/packages/my_packages/package.zip -o localpath/package.zip would download a package based on someone who had permissions to read it. For images you need the image path something like http://someserver.com:4502/content/dam/640x960.jpg to get the image, but you would need to add /jcr:content/renditions/original to get the original e.g. http://someserver.com:4502/content/dam/640x960.jpg/jcr:content/renditions/original. You can also change the image path to get a specific rendition of the image, for example http://someserver.com:4502/content/dam/640x960.jpg/jcr:content/renditions/cq5dam.thumbnail.140.100.png gets a 140x100 version of the image.

I had a similar issue trying to download images from AEM to iOS devices. It turns out AEM (at least the instance I'm hitting) requires a referer header; if absent the request is rejected. The problem did not surface with the simulator, just with real devices. This did the trick:
[request setValue: #"https://www.example.com/" forHTTPHeaderField: #"Referer"];

Related

How to set AppClip invocation for URL with QueryParam?

I am trying to set the AppClip invocation for my App which is already released on app store.
I need an url such that it provides me a jobId e.g.: https://example.com/task?jobId=00001.
My use case is that I send the sms with the url https://example.com/task?jobId=00001 to the user, the user clicks on the url and the app gets started. Then for the other user I send the next url with corresponding jobId.
I did setup the AASA file for my domain (contains the JSON with "applinks" and "appclip" objects) which is valid, also the Domain status is valid on App Store Connect. There is a default experience set with title, subtitle, image and action. I also configured an advance experience for the url https://example.com/task.
However, my app clip doesn't get invoked if I access the url from either sms text or safari. :(
I do not have a web page for https://example.com/task therefore I haven't set up the meta data for this.
Is it possible to invoke the AppClip this way? It is really important for me that the URL is dynamic and I pass that jobId every time for each individual booking.
There s no much documentation and I already read at least twice Apple documentation about AppClip.
Because of this:
I do not have a web page for https://example.com/task therefore I haven't set up the meta data for this.
The answer to this:
Is it possible to invoke the AppClip this way?
Is no. Sorry, you need to own the domain you're working with, or at the very least have means to access its CNAME config (thus, be able to induce the owner of that domain to change the CNAME configs to what you want it to be, similar to what branch.io and AppsFlyer does with its users/clients).

Flash ActionScript 3 get auth info within single SWF

I am developing flash application as single swf file, without HTML wrapper (but for sure I have this swf located at my hosting). I have create application at developers section. The problem I have faced is: when I post this SWF to the my wall at FaceBook I can not get any call from this SWF of the URLloader or ExternalItreface.
For example, I need to do Signed Request in order to get user information but I have got Security Error which say that my domain cannot get information from apps.facebook.com
The request I am doing is a simple:
var urlRequest:URLRequest = new URLRequest("http://apps.facebook.com/my_app_name");
Is there any way to inform faceebok that my hosting is a security save?
If you want to grab things cross domain, the easiest way is to use a script on your server. If you're using php, you can easily connect to http://my.domain/my_script.php which can then CURL the info from http://apps.facebook.com/my_app_name or anywhere else. You can then (parse and) pass that info to your swf.
Otherwise, you're going to need permission from the target to add a crossdomain rule for you.

Fetching Contact image from SugarCRM

I'm trying to integrate my rails app with SugarCRM. Is it possible to fetch the Contact picture from SugarCRM using REST API? Please let me know.
To get the profile image for a user do the following:
Call the login method through REST
Call the get_entry_list method through REST, with the following parameters:
Module: Users
Query: users.user_name = 'xxxx'
Select_fields: picture
The response contains the filename for the profile image, which is stored in /uploads.
However, it is not possible to view the image in that folder due to .htaccess restrictions for security reasons, but other options exist:
Extend the REST API with a method to serve profile images (similar to get_document_revision)
Login on the server from your rails app and get the image
Create a simple entrypoint+module in SugarCRM, which can show the picture
Remove the .htaccess restiction for images (if it doesn't create a security risk in your setup)
In such scenario, I faced a problem where the upload folder stores file with name of the record id, i.e the GUID without file extension.
So to cop up with this I did write a function to copy the file at same hierarchy but with its extension.
Example:
A png extension file at upload folder with name say, '32sdft-tg35f-Tuhis-675rtyf-77666-46dgc' will end up as, '32sdft-tg35f-Tuhis-675rtyf-77666-46dgc.png'
Now only the path will be require to render the image.
Rest all things as applicable as suggested by our friend, Kare !!

Codeigniter Facebook app POST method AND query_string

I have a toy facebook app I'm playing with so I can understand how it all works. It's fine if you go the the app like this: http://apps.facebook.com/pushup-challenge/ (and connect it). But if you then go to it from your facebook page, FB uses the URL http://apps.facebook.com/pushup-challenge/?ref=bookmarks.
In my log file, I see that FB is POSTing the data and including the /?ref=bookmarks to it's call to my codeigniter system. This is causing it to either say "invalid URI parameters" or give me a 404, depending on if I've edited the system/core/URI.php file to add rawurlencode() to a particular call.
I've tried using mod_rewrite to get rid of the query_string, too, but since it's POSTing, it doesn't appear to be working (though I'm not exactly sure why).
Has anyone else run into this? How did you fix it?
Thanks in advance,
Hans
try $config['uri_protocol'] = “PATH_INFO”; and set enable_query_strings = TRUE
or
set
$config['permitted_uri_chars'] = 'a-z 0-9~%.:_\-?=';
in config.php
Because it isn't calling your file by name (just ?ref=bookmarks) the server runs thru the standard default files: index.htm, index.html, index.asp. Because you need to accept a POST, you need a server that allows POSTs to htm & html if you choose to use those. Index.asp will accept POSTs on most servers, and that works for me.
SOLUTION: Add a file (index.asp), that calls the real app that you named in the App settings.

Executing custom code on click on DGML node

Is it possible to execute a piece of C# code when the node of a DGML diagram is double clicked?
It is possible to navigate to an url, I could create a local web site (on127.0.0.1) where you request an URL which executes a command. Problem is that I would like to execute a PowerShell function in the NuGet console...
Any ideas?
You cannot execute custom code, since that would make DGML a security threat when you send it in email, but you can put a “Reference” attribute containing a URL value on a node and when the user double clicks that node the URL is opened. For more information, see How to: Edit and Customize Graph Documents.