• vanathi v
  • NEWBIE
  • 5 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 1
    Likes Given
  • 1
    Questions
  • 3
    Replies
Hi,

I have a requirement to upload a file from SalesForce to Box, While uploading i can upload only file size less than 1MB.

Reason : We have Callout Limits
              But from spring 2015 callout limits have been increased from 3MB to 6MB

But still am getting the same error. We have heap Size, But Still it should upload 3-4MB without IO Exception error.
Have anyOne Solved this issue.Please let me know, it would be of great help.
I have problem of  "no protocol: /upload/drive/v2/Export.csv?uploadType=multipart HTTP/1.1 "  & I have set of Url is --request.setEndpoint('/upload/drive/v2/'+Drvfilename+'?uploadType=multipart HTTP/1.1'); my file Name is Drvfilename

 

 

Hi 

 

I want to upload  a word document  on Box( External Storage)  using Rest API calls  . 

 

Since i need blob as a valid UTF -8 string I am encoding first in base 64 using Encoding util class and then decoding it back as a blob and sending request using req.setbodyasblob() , 

 

I have used all the required parameters but I am getting below invalid request error .

 

{"type":"error","status":400,"code":"invalid_request_parameters","help_url":"http:\/\/developers.box.com\/docs\/#errors","message":"Invalid input parameters in request","request_id":"10130606285252db06ef703"}

 

can someone help ?

 

 

 

  public HTTPResponse uploadFile3()
{

   Document file =[Select Body, BodyLength, Id, Name, Type, ContentType From Document ];
      
      
        
       
        String p_fileName =file.Name+'.'+file.Type;
        String parent_id = '1121945745';
        String boundary = 'AaBbCcX30';
       
      
        
        
        String header = 'Content:\r\n--' + Boundary + '\r\n'+'Content-Disposition: form-data; name="files";filename="'+p_fileName+ '"\r\n'+ 'Content-Type:'+file.ContentType+'\r\n\r\n';
        header += '--' + Boundary +'\r\n'+'Content-Disposition: form-data; name="parent_id"'+'\r\n\r\n'+'0'+'\r\n' ;
         
        
       
        system.debug('header' +header);
        String footer = '\n--'+boundary+'--';
        system.debug('footer' +footer);
  // no trailing padding on header by adding ' ' before the last "\n\n" characters
  String headerEncoded = EncodingUtil.base64Encode(Blob.valueOf(header+'\n\n'));
  system.debug('headerEncoded' +headerEncoded);
  //this ensures no trailing "=" padding
  while(headerEncoded.endsWith('='))
  {
   header+=' ';
   headerEncoded = EncodingUtil.base64Encode(Blob.valueOf(header+'\n\n'));
   system.debug('headerEncoded@1' +headerEncoded);
  }
  //base64 encoded body
  String bodyEncoded = EncodingUtil.base64Encode(file.body);
  system.debug('bodyEncoded' +bodyEncoded);
  //base64 encoded footer
  String footerEncoded = EncodingUtil.base64Encode(Blob.valueOf(footer));
    system.debug('footerEncoded' +footerEncoded);
  Blob bodyBlob = null;
  //last encoded body bytes
  String last4Bytes = bodyEncoded.substring(bodyEncoded.length()-4,bodyEncoded.length());
  system.debug('last4Bytes' +last4Bytes);
  //if the last 4 bytes encoded base64 ends with the padding character (= or ==) then re-encode those bytes with the footer
  //to ensure the padding is added only at the end of the body
  if(last4Bytes.endsWith('='))
  {
   system.debug('inside last4 bytes');
   Blob  decoded4Bytes = EncodingUtil.base64Decode(last4Bytes);
   HttpRequest tmp = new HttpRequest();
   tmp.setBodyAsBlob(decoded4Bytes);
   String last4BytesFooter = tmp.getBody()+footer;   
   system.debug('inside last4 bytes@1'+last4BytesFooter);
   system.debug('inside last4 bytes@3'+EncodingUtil.base64Encode(Blob.valueOf(last4BytesFooter)));
   system.debug('inside last4 bytes@2'+ bodyEncoded.substring(0,bodyEncoded.length()-4));
  
   bodyBlob = EncodingUtil.base64Decode(headerEncoded+bodyEncoded.substring(0,bodyEncoded.length()-4)+EncodingUtil.base64Encode(Blob.valueOf(last4BytesFooter)));
   system.debug('bodyBlob' +bodyBlob);
  }
  else
  {
   bodyBlob = EncodingUtil.base64Decode(headerEncoded+bodyEncoded+footerEncoded);
  }
   
//  if(bodyBlob.size()>3000000)
//  { 
   //this a "public class CustomException extends Exception{}"
 //  throw new CustomException('File size limit is 3 MBytes');
 // }
   
    Http h = new Http();
        HttpRequest req = new HttpRequest();
        string sUrl = 'https://upload.box.com/api/2.0/files/content';
        req.setHeader('Authorization', 'Bearer ' + accessToken);
        req.setHeader('Content-Type','multipart/form-data;boundary='+boundary);
        req.setHeader('Content-Encoding','base64');
      
        req.setEndpoint(sUrl);
        
        req.setMethod('POST');
        req.setBodyAsBlob(bodyBlob);
        System.debug('LAST ENCODING: '+EncodingUtil.base64Encode(req.getBodyAsBlob()));
  
   HttpResponse res;
        if(!Test.isRunningTest()){
            res = h.send(req);
        }
        else{
             res = new HttpResponse();
        }
        valuetoShow = 'Get Doc: ' + res.getBody(); 
        return res;
      

 

Hello all,

 

Can you please let me know the steps to make sure that I run the batch apex every 30 minutes all day and everyday...In the UI i can schedule everyday but here i want to execute my batch class everyday and on each and every single day i have to run this Batch Apex every 30 minutes?Please let me know the sequence of actions that i need to take...

 

Here is my schedulable class

 

 

global class ProcessAccs implements Schedulable{
   
    global void execute(SchedulableContext sc) {
        //  Instantiate batch class 
        BatchProcessAccs B = new BatchProcessAccs();
        database.executebatch(B,200);
    }
    
}

 

 

Hi 

 

I want to upload  a word document  on Box( External Storage)  using Rest API calls  . 

 

Since i need blob as a valid UTF -8 string I am encoding first in base 64 using Encoding util class and then decoding it back as a blob and sending request using req.setbodyasblob() , 

 

I have used all the required parameters but I am getting below invalid request error .

 

{"type":"error","status":400,"code":"invalid_request_parameters","help_url":"http:\/\/developers.box.com\/docs\/#errors","message":"Invalid input parameters in request","request_id":"10130606285252db06ef703"}

 

can someone help ?

 

 

 

  public HTTPResponse uploadFile3()
{

   Document file =[Select Body, BodyLength, Id, Name, Type, ContentType From Document ];
      
      
        
       
        String p_fileName =file.Name+'.'+file.Type;
        String parent_id = '1121945745';
        String boundary = 'AaBbCcX30';
       
      
        
        
        String header = 'Content:\r\n--' + Boundary + '\r\n'+'Content-Disposition: form-data; name="files";filename="'+p_fileName+ '"\r\n'+ 'Content-Type:'+file.ContentType+'\r\n\r\n';
        header += '--' + Boundary +'\r\n'+'Content-Disposition: form-data; name="parent_id"'+'\r\n\r\n'+'0'+'\r\n' ;
         
        
       
        system.debug('header' +header);
        String footer = '\n--'+boundary+'--';
        system.debug('footer' +footer);
  // no trailing padding on header by adding ' ' before the last "\n\n" characters
  String headerEncoded = EncodingUtil.base64Encode(Blob.valueOf(header+'\n\n'));
  system.debug('headerEncoded' +headerEncoded);
  //this ensures no trailing "=" padding
  while(headerEncoded.endsWith('='))
  {
   header+=' ';
   headerEncoded = EncodingUtil.base64Encode(Blob.valueOf(header+'\n\n'));
   system.debug('headerEncoded@1' +headerEncoded);
  }
  //base64 encoded body
  String bodyEncoded = EncodingUtil.base64Encode(file.body);
  system.debug('bodyEncoded' +bodyEncoded);
  //base64 encoded footer
  String footerEncoded = EncodingUtil.base64Encode(Blob.valueOf(footer));
    system.debug('footerEncoded' +footerEncoded);
  Blob bodyBlob = null;
  //last encoded body bytes
  String last4Bytes = bodyEncoded.substring(bodyEncoded.length()-4,bodyEncoded.length());
  system.debug('last4Bytes' +last4Bytes);
  //if the last 4 bytes encoded base64 ends with the padding character (= or ==) then re-encode those bytes with the footer
  //to ensure the padding is added only at the end of the body
  if(last4Bytes.endsWith('='))
  {
   system.debug('inside last4 bytes');
   Blob  decoded4Bytes = EncodingUtil.base64Decode(last4Bytes);
   HttpRequest tmp = new HttpRequest();
   tmp.setBodyAsBlob(decoded4Bytes);
   String last4BytesFooter = tmp.getBody()+footer;   
   system.debug('inside last4 bytes@1'+last4BytesFooter);
   system.debug('inside last4 bytes@3'+EncodingUtil.base64Encode(Blob.valueOf(last4BytesFooter)));
   system.debug('inside last4 bytes@2'+ bodyEncoded.substring(0,bodyEncoded.length()-4));
  
   bodyBlob = EncodingUtil.base64Decode(headerEncoded+bodyEncoded.substring(0,bodyEncoded.length()-4)+EncodingUtil.base64Encode(Blob.valueOf(last4BytesFooter)));
   system.debug('bodyBlob' +bodyBlob);
  }
  else
  {
   bodyBlob = EncodingUtil.base64Decode(headerEncoded+bodyEncoded+footerEncoded);
  }
   
//  if(bodyBlob.size()>3000000)
//  { 
   //this a "public class CustomException extends Exception{}"
 //  throw new CustomException('File size limit is 3 MBytes');
 // }
   
    Http h = new Http();
        HttpRequest req = new HttpRequest();
        string sUrl = 'https://upload.box.com/api/2.0/files/content';
        req.setHeader('Authorization', 'Bearer ' + accessToken);
        req.setHeader('Content-Type','multipart/form-data;boundary='+boundary);
        req.setHeader('Content-Encoding','base64');
      
        req.setEndpoint(sUrl);
        
        req.setMethod('POST');
        req.setBodyAsBlob(bodyBlob);
        System.debug('LAST ENCODING: '+EncodingUtil.base64Encode(req.getBodyAsBlob()));
  
   HttpResponse res;
        if(!Test.isRunningTest()){
            res = h.send(req);
        }
        else{
             res = new HttpResponse();
        }
        valuetoShow = 'Get Doc: ' + res.getBody(); 
        return res;