• saurabhgupta
  • NEWBIE
  • 0 Points
  • Member since 2010

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 3
    Replies

Hi

 

 

I m stuck in a code .Need some help

 

I have fired a Query on document and stored its body in a blob type variable 'BodyContent'

 

Document Doc =[Select Name, Id, Body From Document ];
        System.debug('Doc' + Doc);
        String FileName = Doc.Name;
        BodyContent=Doc.Body;

 

 

Now I m converting this blob to string using TOString() method     like this

 

String DocBody =  bodyContent.toString();

 

but i need to convert this document or string in 8 bit ASCII format

How can i do this.

Can anyone help?

 

Hi All
 
I m quite new in salesforce Integartion.
I m working on  a Integrating salesforce to watchdox
Watchdox is actually meant for protecting Documents
 
I have the API which I need to used and also I have succeded in esatablishing a connection between watch dox and salesforce using LOGIN
 
Next I need to uplaod the document to the watchdox
 
I m pasting here the my code
 

 

Hi All 

I m quite new in salesforce Integartion.

I m working on  a Integrating salesforce to watchdox

Watchdox is actually meant for protecting Documents 

I have the API which I need to used and also I have succeded in esatablishing a connection between watch dox and salesforce using LOGIN

 Next I need to uplaod the document to the watchdox

 I m pasting here the my code 

 

 

 

Hi All

 

I m quite new in salesforce Integartion.

I m working on  a Integrating salesforce to watchdox

Watchdox is actually meant for protecting Documents

 

I have the API which I need to used and also I have succeded in esatablishing a connection between watch dox and salesforce using LOGIN

 

Next I need to uplaod the document to the watchdox

 

I m pasting here the my code

 

 

public static void getWatchDocs() 

    {

 

 

 

       // String url= 'https://api.watchdox.com/login?User name='+UserName+'&Password='+Password;

        String url= 'https://api.watchdox.com/session';

        Http h = new Http();

       // Instantiate a new HTTP request, specify the method (Post) as well as the endpoint

        HttpRequest req = new HttpRequest();

 

        req.setEndpoint(url + '/' + UserName);

        System.debug(url + '/'+ UserName);

        req.setMethod('POST');

 

       req.setHeader('Content-Type', 'application/json; charset=UTF-8');

       req.setHeader('x-wdox-version', '1.0');

 

       req.setBody(' { \"password\" : \"' + Password + '\" } ');   

       System.debug('request is........' + req.getBody());

       System.debug('request header is........' + req.getHeader('x-wdox-version'));

 

        HttpResponse res;        

        String resURL;

        res = h.send(req);

        String Data = res.getHeader('x-wdox-ssid');

        System.debug('reponse is........' + res);

        System.debug('reponse is........' + res.getBody());

        System.debug('reponse header is........' + res.getHeaderKeys() + '.....'+res.getHeader('x-wdox-ssid'));

        System.debug(data);

        sessid=res.getHeader('x-wdox-ssid');

        getguid();

        //getdocs(res.getHeader('x-wdox-ssid'));

    } 

    public static void getguid()

    {

       String url1= 'https://api.watchdox.com/document';

        Http h1 = new Http();

       // Instantiate a new HTTP request, specify the method (Post) as well as the endpoint

        HttpRequest req1 = new HttpRequest();

 

        req1.setEndpoint(url1);

        System.debug(url1);

        req1.setMethod('GET');

       //req.setHeader('Content-Type', 'application/json; charset=UTF-8');

       req1.setHeader('x-wdox-version', '1.0');

       req1.setHeader('x-wdox-ssid', sessid);//'aB9Ctg5U1t3Z6DYLmk2ShLNFrz4wrnRBBS4unt4deKswTQgOIuwe5DWCpUEu/VWU7d6vBq4.kntvAC02gwc.4ZSCZfkAZs4g5VLiNX1LaU/0');

       System.debug('request header is........' + req1.getHeader('x-wdox-version')); 

       System.debug('request header is........' + req1.getHeader('x-wdox-ssid')); 

 

       HttpResponse res1;        

       String resURL1;

       res1 = h1.send(req1);

       guid=res1.getBody(); 

 

       System.debug(guid);

       uploaddocs();

}

 

public static void uploaddocs()

 

{    

        String subguid=guid.substring(9,45);

        System.debug(subguid);

        String FileName = 'sample.doc.docx';

        //Blob bodyContent=blob.valueof('FileName');

        //system.debug( bodyContent );

        String url2= 'https://api.watchdox.com/document';

 

        Http h2 = new Http();

        HttpRequest req2 = new HttpRequest();

        req2.setEndpoint(url2 + '/' + subguid + '/upload');

        System.debug(url2);

        req2.setMethod('POST');

        req2.setHeader('Content-Type', 'multipart/form-data');

        req2.setHeader('x-wdox-version', '1.0');

        req2.setHeader('x-wdox-ssid', sessid);

 

        // req2.setBody('{ filename= ' + NewDocument + ' ,Data= BYTE[] }'); 

 

        System.debug('request is........' + req2.getBody()); 

        HttpResponse res2;        

        String resURL2;

        res2 = h2.send(req2); 

 

}

 

}

 

 

 

But in this code in upload docs method I m having errors .

 

When I contacted the watchdox support they provided me the following information which is required to be added

 

The following link http://code.activestate.com/recipes/146306-http-client-to-post-using-multipartform-data/ has an example written in python how a mutlipart request can be manually constructed.

 

For example, suppose I wanted to send the file name "hello.bin" who's content was 10 lines containing the number 12345.

In the header, 

set x-wdox-version to         1.0

set x-wdox-ssid to the ssid you get from the login procedure

set content-type to              multipart/form-data; boundary=----------ThIs_Is_

tHe_bouNdaRY_$

 

The body of the post should be 

 

------------ThIs_Is_tHe_bouNdaRY_$

Content-Disposition: form-data; name="data"; filename="hello.bin"

Content-Type: application/octet-stream

 

12345

12345

12345

12345

12345

12345

12345

12345

12345

12345

 

------------ThIs_Is_tHe_bouNdaRY_$--

Since I m quite new in using web services and not even aware of phython i want to translate this information in Apex syntax

For req.Header i have written the Apex syntax

but facing problems in using req.Body ( ) in Apex syntax for the above requirement.Actually I need to pass filename and file data in request Message Body

May be I have to use Blob here .

Can anyone help please?

 

 

 

 

Thanks 

Hi

 

 

I m stuck in a code .Need some help

 

I have fired a Query on document and stored its body in a blob type variable 'BodyContent'

 

Document Doc =[Select Name, Id, Body From Document ];
        System.debug('Doc' + Doc);
        String FileName = Doc.Name;
        BodyContent=Doc.Body;

 

 

Now I m converting this blob to string using TOString() method     like this

 

String DocBody =  bodyContent.toString();

 

but i need to convert this document or string in 8 bit ASCII format

How can i do this.

Can anyone help?

 

Hi All
 
I m quite new in salesforce Integartion.
I m working on  a Integrating salesforce to watchdox
Watchdox is actually meant for protecting Documents
 
I have the API which I need to used and also I have succeded in esatablishing a connection between watch dox and salesforce using LOGIN
 
Next I need to uplaod the document to the watchdox
 
I m pasting here the my code
 

 

Hi All 

I m quite new in salesforce Integartion.

I m working on  a Integrating salesforce to watchdox

Watchdox is actually meant for protecting Documents 

I have the API which I need to used and also I have succeded in esatablishing a connection between watch dox and salesforce using LOGIN

 Next I need to uplaod the document to the watchdox

 I m pasting here the my code 

 

 

 

Hi All

 

I m quite new in salesforce Integartion.

I m working on  a Integrating salesforce to watchdox

Watchdox is actually meant for protecting Documents

 

I have the API which I need to used and also I have succeded in esatablishing a connection between watch dox and salesforce using LOGIN

 

Next I need to uplaod the document to the watchdox

 

I m pasting here the my code

 

 

public static void getWatchDocs() 

    {

 

 

 

       // String url= 'https://api.watchdox.com/login?User name='+UserName+'&Password='+Password;

        String url= 'https://api.watchdox.com/session';

        Http h = new Http();

       // Instantiate a new HTTP request, specify the method (Post) as well as the endpoint

        HttpRequest req = new HttpRequest();

 

        req.setEndpoint(url + '/' + UserName);

        System.debug(url + '/'+ UserName);

        req.setMethod('POST');

 

       req.setHeader('Content-Type', 'application/json; charset=UTF-8');

       req.setHeader('x-wdox-version', '1.0');

 

       req.setBody(' { \"password\" : \"' + Password + '\" } ');   

       System.debug('request is........' + req.getBody());

       System.debug('request header is........' + req.getHeader('x-wdox-version'));

 

        HttpResponse res;        

        String resURL;

        res = h.send(req);

        String Data = res.getHeader('x-wdox-ssid');

        System.debug('reponse is........' + res);

        System.debug('reponse is........' + res.getBody());

        System.debug('reponse header is........' + res.getHeaderKeys() + '.....'+res.getHeader('x-wdox-ssid'));

        System.debug(data);

        sessid=res.getHeader('x-wdox-ssid');

        getguid();

        //getdocs(res.getHeader('x-wdox-ssid'));

    } 

    public static void getguid()

    {

       String url1= 'https://api.watchdox.com/document';

        Http h1 = new Http();

       // Instantiate a new HTTP request, specify the method (Post) as well as the endpoint

        HttpRequest req1 = new HttpRequest();

 

        req1.setEndpoint(url1);

        System.debug(url1);

        req1.setMethod('GET');

       //req.setHeader('Content-Type', 'application/json; charset=UTF-8');

       req1.setHeader('x-wdox-version', '1.0');

       req1.setHeader('x-wdox-ssid', sessid);//'aB9Ctg5U1t3Z6DYLmk2ShLNFrz4wrnRBBS4unt4deKswTQgOIuwe5DWCpUEu/VWU7d6vBq4.kntvAC02gwc.4ZSCZfkAZs4g5VLiNX1LaU/0');

       System.debug('request header is........' + req1.getHeader('x-wdox-version')); 

       System.debug('request header is........' + req1.getHeader('x-wdox-ssid')); 

 

       HttpResponse res1;        

       String resURL1;

       res1 = h1.send(req1);

       guid=res1.getBody(); 

 

       System.debug(guid);

       uploaddocs();

}

 

public static void uploaddocs()

 

{    

        String subguid=guid.substring(9,45);

        System.debug(subguid);

        String FileName = 'sample.doc.docx';

        //Blob bodyContent=blob.valueof('FileName');

        //system.debug( bodyContent );

        String url2= 'https://api.watchdox.com/document';

 

        Http h2 = new Http();

        HttpRequest req2 = new HttpRequest();

        req2.setEndpoint(url2 + '/' + subguid + '/upload');

        System.debug(url2);

        req2.setMethod('POST');

        req2.setHeader('Content-Type', 'multipart/form-data');

        req2.setHeader('x-wdox-version', '1.0');

        req2.setHeader('x-wdox-ssid', sessid);

 

        // req2.setBody('{ filename= ' + NewDocument + ' ,Data= BYTE[] }'); 

 

        System.debug('request is........' + req2.getBody()); 

        HttpResponse res2;        

        String resURL2;

        res2 = h2.send(req2); 

 

}

 

}

 

 

 

But in this code in upload docs method I m having errors .

 

When I contacted the watchdox support they provided me the following information which is required to be added

 

The following link http://code.activestate.com/recipes/146306-http-client-to-post-using-multipartform-data/ has an example written in python how a mutlipart request can be manually constructed.

 

For example, suppose I wanted to send the file name "hello.bin" who's content was 10 lines containing the number 12345.

In the header, 

set x-wdox-version to         1.0

set x-wdox-ssid to the ssid you get from the login procedure

set content-type to              multipart/form-data; boundary=----------ThIs_Is_

tHe_bouNdaRY_$

 

The body of the post should be 

 

------------ThIs_Is_tHe_bouNdaRY_$

Content-Disposition: form-data; name="data"; filename="hello.bin"

Content-Type: application/octet-stream

 

12345

12345

12345

12345

12345

12345

12345

12345

12345

12345

 

------------ThIs_Is_tHe_bouNdaRY_$--

Since I m quite new in using web services and not even aware of phython i want to translate this information in Apex syntax

For req.Header i have written the Apex syntax

but facing problems in using req.Body ( ) in Apex syntax for the above requirement.Actually I need to pass filename and file data in request Message Body

May be I have to use Blob here .

Can anyone help please?

 

 

 

 

Thanks