Unable to upload image to a Coldfusion REST API Service - rest

I am using CF10 REST API Service and trying to upload an a profile picture for a user.
The service method tries to save this image to a destination:
<cfcomponent rest="true"
restpath="/users">
<cffunction name="saveProfilePicture"
access="remote"
httpmethod="POST"
restpath="{userid}/profilePicture"
returntype="any">
<cfargument name="uploadedImage" required="true"/>
<cfargument name="userid" required="true" restargsource="Path"/>
<cffile
action="upload"
destination="#upload_path#"
fileField="uploadedImage"
result="profilePicture"
accept="image/jpg"
/>
</cffunction>
</cfcomponent>
I am trying to call this service as follows:
<form method="POST" enctype="multipart/form-data" action="#path#/users/#userid#/profilePicture">
<input type="file" name="uploadedImage"/>
<input type="submit" name="btn_submit_profilePicture" id="btn_submit_profilePicture"
value="Submit"/>
</form>
After I make this call I get an error message "Unsupported Media Type".
I get the same issue if I use cfhttp:
<cfhttp url="#path#/users/#userid#/profilePicture"
result="restResult" method="POST" multipart="true">
<cfhttpparam file="someimage.jpg" mimetype="image/jpg"
name="uploadedImage" type="file"/>
</cfhttp>
I have tried to search around but couldn't find a solution that works.
I can't use a framework as of now as most of the API is already implemented over CF REST API so guess I am stuck with it.
Any help would be greatly appreciated. Thanks.

Change your code like the following and test it.
<cfcomponent rest="true"
restpath="/users">
<cffunction name="saveProfilePicture"
access="remote"
httpmethod="POST"
restpath="{userid}/profilePicture"
returntype="any">
<cfargument name="uploadedImage" restargsource="form"/>
<cfargument name="userid" restargsource="Path"/>
<cffile
action="upload"
destination="#upload_path#"
result="arguments.uploadedImage"
accept="image/jpg,image/jpeg"
/>
</cffunction>
</cfcomponent>

Related

FORM POST TO EXTERNAL URL -NEED HTTP BUT ALWAYS IN HTTPS-

In a AURA Lightining component,i need to implement a POST with a FORM, and the target Endpoint is in HTTP and not in HTTPS.
Here the code:
on submitForm:
cmp.find("formFirma").getElement().submit();
The problem is that when i click on button,the browser open the new tab always in https and doesn't find the external resource.
Even if POST should be always in HTTPS,is there a way to this HTTP?
if a do a "GET" with :
'''
var urlEvent = $A.get("e.force:navigateToURL");
urlEvent.setParams({
"url": "http://endpoint"
});
urlEvent.fire();
'''
it works in HTTP.
Thanks
<div onclick="{!c.submitForm}">
<form name="formFirma1" target="_blank" forceSSL="false" aura:id="formFirma" action="http://endpoint" method="POST">
<input type="hidden" name="idVerbale" value="191" />
<input type="hidden" name="CUAA" value="12345AB" />
<input type="hidden" name="TipoUtente" value="Agronomo" />
<lightning:button label="Firma" />
</form></div>
Here is the markup

CAS - Redirect to custom login page when credentials are wrong

Good morning.
I've successfully configured a CAS SSO server and client. However, I want to change CAS' configurations to use a custom login page. I followed this tutorial to make such configuration and it works like a charm. But, the problem is that when I enter invalid credentials (wrong username or password) it tries to redirect to the CAS' default login page; however, it should redirect to the custom external login page. I would really appreciate if you help me to find out how to make CAS to redirect to a different page when wrong credentials are entered.
This is my casLoginView.jsp
<%# page contentType="text/html; charset=UTF-8" %>
<html>
<head>
<script type="text/javascript">
function doAutoLogin() {
document.forms[0].submit();
}
</script>
</head>
<body onload="doAutoLogin();">
<form id="credentials" method="POST" action="https://externalsite.com/cas-server-webapp-4.0.0/login?service=<%= request.getParameter("service") %>">
<input type="hidden" name="lt" value="${loginTicket}" />
<input type="hidden" name="execution" value="${flowExecutionKey}" />
<input type="hidden" name="_eventId" value="submit" />
<input type="hidden" name="username" value="<%= request.getParameter("username") %>" />
<input type="hidden" name="password" value="<%= request.getParameter("password") %>" />
<% if ("true".equals(request.getParameter("rememberMe"))) {%>
<input type="hidden" name="rememberMe" value="true" />
<% } %>
<input type="submit" value="Submit" style="visibility: hidden;" />
</form>
</body>
And this is my external custom login page:
<form method="GET" action="https://externalsite.com/cas-server-webapp-4.0.0/">
<p>Username : <input type="text" name="username" /></p>
<p>Password : <input type="password" name="password" /></p>
<p>Remember me : <input type="checkbox" name="rememberMe" value="true" /></p>
<p><input type="submit" value="Login !" /></p>
<input type="hidden" name="auto" value="true" />
<input type="hidden" name="service" value="<%= request.getParameter("service") %>" />
</form>
Basically my external login page sends the credentials to the CAS login page and the latter is submited automatically. However, when credentials are wrong, CAS redirects to the default login page and not to my external login page.
Regards.
You need change the code at login-webflow.xml in cas-server-webapp.
The code should be changed as below:
<action-state id="handleAuthenticationFailure">
<!-- Comment FailedLoginException and AccountNotFoundException -->
<!--<transition on="FailedLoginException" to="generateLoginTicket"/>-->
<!--<transition on="AccountNotFoundException" to="generateLoginTicket"/>-->
</action-state>
Add:
<action-state id="customFailedLoginException">
<evaluate expression="generateLoginTicketAction.generate(flowRequestContext)" />
<transition on="generated" to="customFailedLoginExceptionView" />
</action-state>
<view-state id="customFailedLoginExceptionView" view="externalRedirect:#{requestParameters.service}&errorMsg=failedLogin"/>
<action-state id="customAccountNotFoundException">
<evaluate expression="generateLoginTicketAction.generate(flowRequestContext)" />
<transition on="generated" to="customAccoundNotFoundExceptionView" />
</action-state>
<view-state id="customAccoundNotFoundExceptionView" view="externalRedirect:#{requestParameters.service}&errorMsg=notFound" />
Now if you submit a user name that do not exists or a password that is wrong, your would get a response url with a parameter called 'errorMsg'.
I also make a sample about how to login cas with client custom login screen rather than server login srceen. You could download it on
https://github.com/yangminxing/cas-custom-login-page
I solved my problem by changing the transitions on the login-webflow.xml file. What I did was to create a new action state:
<action-state id="customFailedLogin">
<evaluate expression="generateLoginTicketAction.generate(flowRequestContext)" />
<transition on="generated" to="externalRedirection" />
</action-state>
and this one calls a view-state which redirects the user to my external login page
<view-state id="externalRedirection" view="externalRedirect:#{requestParameters.callingUrl}&error=true"/>
(callingUrl is a variable that I created and sent with the service url). At the end I just changed the transition in the handleAuthenticationFailure
<transition on="AccountNotFoundException" to="customFailedLogin"/>
<transition on="FailedLoginException" to="customFailedLogin"/>
Hope it helps to someone else.

PayPal DoCapture “you don’t have permission to make this API call” Error

I have tested doCapture API call by using the following form
<form method=post action=https://api-3t.sandbox.paypal.com/nvp>
<input id="METHOD" name="METHOD" type="hidden" value="DoCapture" />
<input id="AUTHORIZATIONID" name="AUTHORIZATIONID" type="hidden" value="4M894622FJ6713130" />
<input id="AMT" name="AMT" type="hidden" value="50" />
<input id="CURRENCYCODE" name="CURRENCYCODE" type="hidden" value="EUR" />
<input id="COMPLETETYPE" name="COMPLETETYPE" type="hidden" value="NotComplete" />
<input type=submit value=DoCapture>
But it show the following result
TIMESTAMP=2013%2d08%2d08T04%3a42%3a31Z&CORRELATIONID=d5019d565a403&ACK=Failure&VERSION=0%2e000000&BUILD=7161310&L_ERRORCODE0=10002&L_SHORTMESSAGE0=Authentication%2fAuthorization%20Failed&L_LONGMESSAGE0=You%20do%20not%20have%20permissions%20to%20make%20this%20API%20call&L_SEVERITYCODE0=Error
How can I set permission to make this API Call?
Thanks in Advance
Lakshmi Priya.K
You need to include VERSION, USER, PWD, and SIGNATURE in your call.

posting data using html in iphone

In website the form data is posted using the code below using HTML post request:
<div id="requestinfo">
<form method="post" action="http://abc/form-post.php" id="request_form">
<input type="hidden" name="field1" value="value1" />
<input type="hidden" name="field2" value="value2" />
</form>
</div>
How can I do the same in iPhone? We do not have to use web services.
I'd recommend using AFNetworking as a solution for working with HTTP verbs and data.
The AFHTTPClient allows you to specify the verb (POST in this case) as well as the parameters to pass.
See: AFNetworking Post Request

jsf2: form: GET method

I am trying to construct equivalent of this code in JSF2
<form action="/search.xhtml" method="get">
<div class="search">
<input type="hidden" name="mutation" value="#{facesContext.viewRoot.locale}" />
<input name="searchString" class="text" />
<input type="submit" class="searchSubmit" value="#{msg.searchIt}" />
</div>
</form>
The point of this construction is to redirect user to the search.html page, which shows the search results. The page uses URL params to decode the searchString and language mutation.
And because it uses get, it is also bookmarkable.
With JSF2 I tried to use the h:button with param for the mutation, but I dont have a clue, how to force jsf to encode the h:inputText searchString.
Thanks for your help.
As far as I know, there is no possibility to use method="GET" in JSF.
It is not what you exactly want, but may be using post-redirect-get pattern can solve your issue:
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core">
<f:metadata>
<f:viewParam name="searchString" value="#{requestScopedBean.searchString}"/>
<f:viewParam name="mutation" value="#{requestScopedBean.mutation}"/>
</f:metadata>
<h:body>
<h:form>
<h:inputText value="#{requestScopedBean.searchString}"/>
<h:commandButton value="submit" action="/tests/search?faces-redirect=true&includeViewParams=true">
<f:param name="mutation" value="whatever"/>
</h:commandButton>
</h:form>
</h:body>
</html>
More about PRG pattern in JSF2 in this article: http://www.warski.org/blog/?p=185