02-24-2019 09:43 PM
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 ?
02-25-2019 01:04 AM
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
02-25-2019 01:04 AM
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
02-25-2019 02:44 AM
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 ?
02-25-2019 07:38 AM
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}"
}
02-28-2019 07:49 PM
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.
Explore our Alfresco products with the links below. Use labels to filter content by product module.