cancel
Showing results for 
Search instead for 
Did you mean: 

angular-nuxeo : attach a blob through uploader ? - [SOLVED]

freemann_
Star Contributor
Star Contributor

Hi,

I try to use angular-nuxeo to attach a blob, but I get excute exception.

Here is my code :

documentUploader(uid: string, file : File): IPromise<Object> { 
	let defer = this.$q.defer(); 
	let options : any = {}; 
	options.operationId = 'Blob.Attach'; 
	options.client = this.nuxeo; 
	let myUploader : any; 
	myUploader = this.nuxeoClient.uploader.execute(options)
		.params({ 
			document: uid, 
			save : true, 
			xpath: "file:content" 
		}); 
	myUploader.uploadFile(file)
	.then((resp) => {
		 defer.resolve(resp); 
	}, 
	(error) => { 
		defer.reject(error); 
	} ); 
	return defer.promise;
}

How to instanciate the Uploader and then attached the blob?

Thanks for help

1 ACCEPTED ANSWER

Thomas_Roger
Star Contributor
Star Contributor

If you are in an Angular (1.x) application, you should register the client as an Angular service:

...
.service('nuxeo', function() {
  return new Nuxeo({
    baseURL: 'http://localhost:8080/nuxeo/',
    auth: {
      method: 'basic',
      username: 'Administrator',
      password: 'Administrator'
    }
  });
})

And then, you can inject nuxeo in your controllers to use the client, such as other Angular services you may already use.

View answer in original post

16 REPLIES 16

Thomas_Roger
Star Contributor
Star Contributor

Hi,

First, you should use the last version of nuxeo-js-client that works within an Angular application, angular-nuxeo is not needed anymore. See the Angular Applications section.

Then, see the BatchUpload section, that contains a sample of exactly what you want to do "Attach an uploaded blob to a document".

freemann_
Star Contributor
Star Contributor

Hi,

After done 'bower install nuxeo --save' , I tried to declare 'Nuxeo' as module in app.js but got error :

Error: [$injector:nomod] Module 'Nuxeo' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument.

I declared in index.html ==>

nuxeo/dist/nuxeo.js

Thanks for help

freemann_
Star Contributor
Star Contributor

Hi Thomas,

In the readMe you say :

When added to your page, `Nuxeo` is available as a global variable.
var nuxeo = new Nuxeo({ ... });

What do you mean by added to your page , I don't see ? referencing it in app.js ? I saw that there is no angular.module in the new library.

Thanks for help

Thomas_Roger
Star Contributor
Star Contributor

If you are in an Angular (1.x) application, you should register the client as an Angular service:

...
.service('nuxeo', function() {
  return new Nuxeo({
    baseURL: 'http://localhost:8080/nuxeo/',
    auth: {
      method: 'basic',
      username: 'Administrator',
      password: 'Administrator'
    }
  });
})

And then, you can inject nuxeo in your controllers to use the client, such as other Angular services you may already use.

freemann_
Star Contributor
Star Contributor

Hi,

I though that there was a module in the nuxeo js library, to declare in the main app.js and use it globaly in the angular app.

I go to follow your recommandation and create and simple .js service file and not a .ts file.

Thanks a lot for your quick reply

freemann_
Star Contributor
Star Contributor

Hi Thomas, it works fine but I have a little problem.

When I want to fetch documents, the nuxeo server requires automation user/pwd even if I use client.connect() in my code : here is an example :

//Ici on liste tous les documents du WS DOEJ
function ListerLesDocumentsNuxeo() { 
   var defer = $q.defer();    
   //On force la connection ??    
   nuxeoClientConnect().then(function (resp) {
        console.log('Connection ok ', resp.connected);        
       nuxeoClient.operation('Document.GetChildren')            
        .input(nuxeoPath)            
        .execute()            
    .then(function (docs) {                
         defer.resolve(docs);            
     }).catch(function (error) {                
         defer.reject(error);                
         throw error;            
     });    
   });    
return defer.promise;
}

We use CAS on the nuxeo server so on client.connect(), we have this exception : Fetch API cannot load http://nuxeo.server/nuxeo/json/cmis. The request was redirected to 'https://cas.server/cas/login?service=http%3A%2F%2Fnuxeo.server%2Fnuxeo%2Fnxstartup.faces', which is disallowed for cross-origin requests that require preflight. Thanks for Help

You should deploy your Angular application on the Nuxeo Server, and put your application URL behind the Authentication filter so that the user will need to log in through CAS before accessing the app.

"put your application URL behind the Authentication filter", Can I have an example? Thanks

You could have a look at those projects https