05-31-2017 09:40 AM
Hi,
I'm trying to use the https://www.npmjs.com/package/alfresco-js-api to build an application (Node) aiming to create files in Alfresco.
I have a Community Edition Alfresco installed.
let AlfrescoApi = require('alfresco-js-api');
let alfrescoJsApi = new AlfrescoApi();let fs = require('fs');
alfrescoJsApi.login('admin', 'admin').then(function (data) {
console.log('API called successfully login ticket:' + data);
}, function (error) {
console.log("Error, cannot connect to Alfresco");
});var fileToUpload = fs.createReadStream('./testFile.txt');
alfrescoJsApi.upload.uploadFile(fileToUpload)
.then(function () {
console.log('File Uploaded');
}, function (error) {
console.log('Error during the upload' + error);
});
Previous code doesn't work and I don't know why, I can create a folder with " alfrescoJsApi.nodes.createFolder(); " but cannot manage to create a file.
In log I'm obtaining following error :
Error during the uploadError: {"error":{"errorKey":"Required parameters are missing","statusCode":400,"briefSummary":"04310053 Required parameters are missing","stackTrace":"Pour des raisons de sécurité, le traçage de la pile n'est plus affiché, mais la propriété est conservée dans les versions précédente.","descriptionURL":"https://api-explorer.alfresco.com"}}
If anyone have any idea of what I'm doing wrong 😕
Thanks in advance
06-02-2017 08:50 AM
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
06-01-2017 10:22 AM
...hmmm, your alfresco and alfresco-js-api version is?
06-01-2017 10:27 AM
Alfresco Community v5.2.0
"alfresco-js-api": "^1.5.0"
06-02-2017 04:38 AM
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
06-02-2017 08:50 AM
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
06-02-2017 12:48 PM
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.
06-07-2017 05:21 PM
It would be helpful if you could share your experience in July.
Explore our Alfresco products with the links below. Use labels to filter content by product module.