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

Hi Thomas,

freemann_
Star Contributor
Star Contributor

Hi Thomas,

I think I found a little bug for Nuxeo.auth. When instanciate like this, Nuxeo._auth is always undefined :

//Instanciation de l'Object Nuxeo de la librairie
	var nuxeoClient = new Nuxeo({
	    baseURL: nuxeoUri,    
	    apiPath: nuxeoApi,
            auth : {    
                 method: 'basic',    
                 username: nxUser,    
                 password: nxPwd
            },    
           //Activation du CORS    
          headers: defaultHeader
      });

So I force the Auth like this and then nuxeoClient.connect(), fetch documents successfuly ;

/*Bug authentification ??
A voir Avec ToRoger de chez Nuxeo 
*/
function forcerLAuth() {
    nuxeoClient._auth =  authentication;
}

Registering a "nuxeo service" as below works correctly, and I can do fetch requests

So, it's not possible to use a variable directly for 'auth' ? it works fine for 'baseURL', 'apiPath' and 'headers'.

Could you share your full code in a gist or something? I don't understand what you want to achieve.

Here is a sample of my code

freemann_
Star Contributor
Star Contributor

Hi Thomas,

Do you have something for me about "put your application URL behind the Authentication filter" for using angular with nuxeo on jasig CAS nuxeo server?

A sample or example.

Thanks