1

Hi All,
When End User Click the Command button need to genearte the dynamic CSV File using apex and uploading into Drop Box account. Hereby my code as follows,

 public class DropboxController
{


    public DropboxController()
    {

    }

    public PageReference DropAuth()
    {
        string body= 'Test';

        List<Account > acclist = [Select id,name , CreatedDate , lastModifiedDate from Account limit 10];
        string header = 'Record Id, Name , Created Date, Modified Date \n';
        string finalstr = header ;
        for(Account a: acclist)
        {
               string recordString = '"'+a.id+'","'+a.Name+'","'+a.CreatedDate+'","'+a.LastModifiedDate +'"\n';
               finalstr = finalstr +recordString;
        }
        blob csvBlob = Blob.valueOf(finalstr);
        System.debug('CSV :' + finalstr);
        HttpRequest request = new HttpRequest();
        request.setMethod('POST');
        request.setEndpoint('https://content.dropboxapi.com/1/files_put/auto/home');
        Blob headerValue = Blob.valueOf('5na5z4tgwqgqee3' + ':' + 'xnpy19zr575uw9l');
        String authorizationHeader = 'BASIC ' + EncodingUtil.base64Encode(headerValue);
        request.setHeader('Authorization', authorizationHeader);   
        request.setBodyAsBlob(csvBlob);

        System.debug(request);

        Http hp = new Http();
        HttpResponse response = hp.send(request);

        System.debug(' RESP ::: ' + response.getBody());

      return null;
    }


}

Error : {"error": "Body may not be empty"}

Please advice..where am doing wrong ?

Thanks, Vivek.K

  • This is just a hunch, but I think you may need to specify a Content-Length header. Something like request.setHeader('Content-Length', csvBlob.size()); – rael_kid May 2 '16 at 9:24
  • Hi All, I got the solution.unable to post the full code here. – vivek viki May 4 '16 at 4:06
  • For reference ,My Working code Link -> developer.salesforce.com/forums/… – vivek viki May 4 '16 at 10:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.