cancel
Showing results for 
Search instead for 
Did you mean: 

How to upload a file from a CUSTOM SHARE PAGE ?

paulclinton
Confirmed Champ
Confirmed Champ

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 ?

1 ACCEPTED ANSWER

sanjaybandhniya
Elite Collaborator
Elite Collaborator

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

View answer in original post

4 REPLIES 4

sanjaybandhniya
Elite Collaborator
Elite Collaborator

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.