You need to sign in to do that
Don't have an account?
sukanta 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();
@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();
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
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);