Uploading a file through JS API

cancel
Showing results for 
Search instead for 
Did you mean: 
mehe
Senior Member II

Re: Uploading a file through JS API

Jump to solution

...hmmm, your alfresco and alfresco-js-api version is?

alexandreb
Active Member II

Re: Uploading a file through JS API

Jump to solution

Alfresco Community v5.2.0

"alfresco-js-api": "^1.5.0"

alexandreb
Active Member II

Re: Uploading a file through JS API

Jump to solution

Okay, I managed to create a file using REST, doing few changes :

In var options :

'headers': {
        'Content-Type': 'application/json'
        }

Also, the path to upload :

options.path = '/alfresco/api/-default-/public/alfresco/versions/1/nodes/-root-/children?alf_ticket='+JSON.parse(chunk).data.ticket

But I still don't know how to upload an existing file

alexandreb
Active Member II

Re: Uploading a file through JS API

Jump to solution

Okay so I figured out how to upload a File, once logged and var ticket initialized :

var request = require('request')
var fs = require('fs')

var r = request.post('http://localhost:8080/alfresco/api/-default-/public/alfresco/versions/1/nodes/-root-/children?alf_ti..., function callback(err, httpResponse, body) {
            if(err || JSON.parse(body).error) {
                return console.log('Upload failed : ' + body)
            }
            console.log('Upload success')
        })

var form = r.form()
form.append("name", "testFile.txt")
form.append("nodeType", "cm:content")
form.append("relativePath", "Sites/test-site/documentLibrary")
form.append("filedata",fs.createReadStream('./testFile.txt'))

I don't use alfresco-js-api anymore

mehe
Senior Member II

Re: Uploading a file through JS API

Jump to solution

Hi Alexandre,

sorry I had no time to answer - I'm using alfresco-js-api with angularJS clients but didn't use the upload function until now (migrating from old stuff, upload is still the old code).

I had some login issues with alfresco-js-api, but after asking under the adf section of alfresco community, my problems were solved in no time.

If you are interested, I will share my experience when using (or trying to use) the upload-function - but this won't be before July.

ethan_wong
Active Member II

Re: Uploading a file through JS API

Jump to solution

It would be helpful if you could share your experience in July.