function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
praveenpropraveenpro 

how to send attachment from php to salesforce and how to insert attachment in salesforce using REST Api?

Hi,
@HttpPost
    global static String createNewAttachments() {
    
        RestRequest req = RestContext.request;        
      
        String optyName=req.requestURI.substring(req.requestURI.lastIndexOf('/')+1);
        Opportunity objOpty= [ Select ID, Name from Opportunity where Name =:optyName limit 1];
        
        String doc=EncodingUtil.Base64Encode(req.requestBody);
        
        
        Attachment a = new Attachment();
        a.ParentId = objOpty.Id;
        a.Name = 'test.doc';
        a.Body = req.requestBody;
        a.ContentType = 'application/vsn.ms-word';
        insert a;
        
        return 'attachment added';
    }

I am able get attachment using Apex REST Api form external system but the file data was not opened properly in the document.