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
sukanta Anbu 7sukanta Anbu 7 

I have a custom object. I want to add a blob file in a POST method. The error when i execute in anonymous window is Method does not exist or incorrect signature: void POST() from the type.

public class leadUploadCtrl {
    
    @AuraEnabled
    public static String POST(Blob file, String jobID) {
        
        Http h = new Http();
        String fileName = 'accounts.csv';
        String url = 'https://csv-file-upload.herokuapp.com/leads/' + jobID;
        String separationString = 'da5cbc76-39ba-4f80-8b81-090b82e90cf0';
        String str = file.toString();
        // decode 
        Blob decodedBlob = EncodingUtil.base64Decode(str);
        // convert to string
        String result = decodedBlob.toString();
        
        // assemble the body payload
        String header = '--' + separationString + '\nContent-Disposition: form-data; name="file"; filename="' + fileName + '"\nContent-Type: application/octet-stream\n\n';
        //String body = EncodingUtil.base64Encode(file) + '\n';
        String body = result + '\n';
        String footer = '--' + separationString + '--';
        String bodyPayload = header + body + footer;
        system.debug('PAYLOAD: ' + bodyPayload);

        HttpRequest req = new HttpRequest();
        req.setHeader('Content-Type', 'multipart/form-data; boundary=' + separationString);
        req.setEndpoint(url);
        req.setMethod('POST');
        req.setBody(bodyPayload);
        system.debug('REQUEST: ' + req);

        // Send the request, and return a response
        HttpResponse res = h.send(req);
        System.debug(res.getBody());
        return res.getBody();
    }
}

In anonymous window i tried to invoke the code as follows:
leadUploadCtrl.POST();
Best Answer chosen by sukanta Anbu 7
David Zhu 🔥David Zhu 🔥
Your Post method has two parameters "Blob file, String JobId".
But your anoymouse apex, uses leadUploadCtrl.POST(); which has not parameters. You have to pass parameters like

Blob blobfile = blob.valueof('test');
String JobId = 'xxxxx'; // assign jobid value
leadUploadCtrl.POST(blobfile, jobId);

All Answers

David Zhu 🔥David Zhu 🔥
Your Post method has two parameters "Blob file, String JobId".
But your anoymouse apex, uses leadUploadCtrl.POST(); which has not parameters. You have to pass parameters like

Blob blobfile = blob.valueof('test');
String JobId = 'xxxxx'; // assign jobid value
leadUploadCtrl.POST(blobfile, jobId);
This was selected as the best answer
sukanta Anbu 7sukanta Anbu 7
@David, thanks a ton. I have figured out the issue and now I am finally able to move the fie to another DB via heroku