2014-06-07 7 views
1

IDOL API를 사용하여 Salesforce Apex 클래스에서 pdf 파일을 html로 변환하고 있습니다. 다음이이 작동IDOL 자료보기

<html> 
    <body> 
     <form action="https://api.idolondemand.com/1/api/sync/viewdocument/v1" 
     method="Post" enctype="multipart/form-data"> 

      <input type="hidden" name="raw_html" value="true"/> 
      <input type="hidden" name="apikey" 
      value="{apikey removed}"/> 
      <input type='FILE' name='file'/><br/> 
      <input type='submit' name='upload_btn' value='Submit'/> 
     </form>   
    </body> 
</html> 

:

것은 내가 좋아하는, 간단한 HTML을 사용하고합니다. 하지만 APEX 코드 httprequest을 사용할 때 잘못된 요청을합니다.

내 APEX 코드는 다음과 같습니다

public HTTPResponse uploadFile(Attachment file){ 

     //String boundary = '---------------------\n'; 
     String header = '\n';    
     header += 'Content-Disposition: form-data; name="file"; filename="' 
        + file.Name +'"\nContent-Type: application/pdf\n\n';    
     String footer = '\n'; 

     String querybody = '\n Content-Disposition: form-data; 
             name="raw_html"\n\n'+true+'\n'; 
     querybody = querybody + '\n Content-Disposition: form-data; 
       name="apikey"\n\n {apikey removed} \n\n'; 

     //base64 encoded body 
     String bodyEncoded = EncodingUtil.base64Encode(file.body); 

     //last encoded body bytes 
     String last4Bytes = 
       bodyEncoded.substring(bodyEncoded.length()-4,bodyEncoded.length()); 
     //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('=')) 
     { 
      Blob decoded4Bytes = EncodingUtil.base64Decode(last4Bytes); 
      HttpRequest tmp = new HttpRequest(); 
      tmp.setBodyAsBlob(decoded4Bytes); 
      String last4BytesFooter = tmp.getBody()+footer; 
      bodyEncoded = querybody + header + 
         bodyEncoded.substring(0,bodyEncoded.length()-4) +    
         EncodingUtil.base64Encode(Blob.valueOf(last4BytesFooter)) + 
          footer; 

     } 
     else 
     { 
      bodyEncoded = querybody + header + bodyEncoded + footer; 
     } 

     bodyEncoded = querybody;// + header + bodyEncoded + footer; 
     System.debug('>>>>>>>>>>>>>>>>>>>>>>' + bodyEncoded);   

     HttpRequest req = new HttpRequest(); 
     req.setHeader('Content-Type','multipart/mixed'); 
     req.setMethod('POST'); 

       req.setEndpoint('https://api.idolondemand.com/1/api/sync/viewdocument/v1' 
      ); 
     req.setBody(bodyEncoded); 
     req.setTimeout(120000);     
     req.setHeader('Content-Length', String.valueof(req.getBody().length())); 
     Http http = new Http(); 
     Httpresponse res = http.send(req);   
     return res; 
    } 

내 비주얼 힘 페이지는 포함 :

<apex:page controller="IDOLService"> 

<apex:form > 
    <apex:pageBlock title="File Input"> 
     <apex:pageBlockSection > 
     <apex:pageBlockSectionItem >   
      <apex:inputFile value="{!file.body}" filename="{!file.Name}"/> 
      <apex:commandButton action="{!showPreview}" value="Show Preview"/>   
     </apex:pageBlockSectionItem> 
     </apex:pageBlockSection>  
    </apex:pageBlock> 

    <apex:outputpanel id="docpanel"> 
     {!result} 
    </apex:outputpanel> 
    </apex:form> 
    </apex:page> 

이것은, 7005의 나에게 잘못된 요청을 오류를주고있다.

+0

아무도이 문제를 직면하지? – Abhi

답변

1

제공된 코드를 사용하여 재생하려고했지만 겉으로 생략 된 나머지 IDOLService 컨트롤러 코드가 없으면 올바르게 재생하기가 어렵습니다. 우리는 apex에서 http로 여러 부분으로 된 폼을 게시하는 것을 시도하지 않았습니다. (그리고 다른 질문을 한 눈에 보면 완전히 단순하지 않다는 것을 알 수 있습니다.) 그래서 작동 예제를 작성하는 데 약간의 시간이 걸릴 것입니다.

idolondemand (at) hp.com에 자세한 정보를 보내면 팀에서보다 자세한 검토를 할 수 있습니까?

감사합니다,

hughesthe1st
(I이 HP 작동)