Hey guys,
What I have done is that I have integrated a scanner in alfresco. What it actually does is, after scanning the document it uploads it to a folder in the document library. For this I have created a custom share page called scanner and in that I have written a javascript which will get the scanned file and upload.
It works fine. But, what is happening is that I'm hard-coding the username and Password in Ajax POST method and hence all the documents uploaded is getting uploaded under Admin name.
Below is the AJAX method I'm using
$.ajax({
username: admin,
password: admin,
url: "/alfresco/api/-default-/public/alfresco/versions/1/nodes/"+alfrescoNodeId+"/children",
method: "POST",
mimeType: "multipart/form-data",
data: form,
async: false,
crossDomain: true,
processData: false,
contentType: false,
success: function(result,status,xhr) {
alert("Content uploaded!");
},
error: function(xhr,status,error) {
console.log("xhr==== "+xhr);
console.log("status==== "+status);
console.log("error==== "+error);
alert("Error: Failed to upload file");
}
});
My question is on how to get the logged in user as the authentication parameters ? Or Is it the right method I'm using to upload the file ?
Solved! Go to Solution.
Hi,
If you are uploading file from share then username and password is not required.
API that you have used that is rest api so it takes username and password.
Other thing you can do is pass ticket with that api.
Thanks,
Sanjay
Hi,
If you are uploading file from share then username and password is not required.
API that you have used that is rest api so it takes username and password.
Other thing you can do is pass ticket with that api.
Thanks,
Sanjay
Thank you for the reply Sanjay.
Yes, I did find a api which would get me the ticket. But to generate the ticket, User Name and Password parameters are required.
Below is the api which I found to generate ticket.
GET /alfresco/s/api/login?u={username}&pw={password?}
Is there any-other way I could get the session ticket ?
Hi,
You can get ticket like this way.
Creare repository side webscript and and call that webscript from share.
## ticket.get.desc.xml
<webscript>
<shortname>Get current ticket</shortname>
<description>Get current ticket</description>
<url>/auth/get-ticket</url>
<format default="json">extension</format>
<authentication>user</authentication>
</webscript>## ticket.get.json.ftl
{
"ticket": "${sessionticket.ticket}"
}
Hi Sanjay,
Sorry for coming back late. Thank you for the help. I did write a webscript to get a ticket and used that ticket along with the REST api to upload the file. It worked fine.
Ask for and offer help to other Alfresco Content Services Users and members of the Alfresco team.
Related links:
By using this site, you are agreeing to allow us to collect and use cookies as outlined in Alfresco’s Cookie Statement and Terms of Use (and you have a legitimate interest in Alfresco and our products, authorizing us to contact you in such methods). If you are not ok with these terms, please do not use this website.