I would like to create an apex service in salesforce that accepts csv files.
Resolved this issue with the following:
Created a public site which the FileUpload class is added. Since I need to create an unauthenticated endpoint. You can also have the authenticated endpoint via creating connectedApp and setup oauth.
Apex service
@RestResource(urlMapping='/api/FileUpload/*')
global with sharing class FileUpload{
@HttpPost
global static void processFile() {
RestRequest req = RestContext.request;
RestResponse res = RestContext.response;
Blob b = req.requestBody;
// Add data processing here based from Blob value
}
}
Client command:
curl -H 'X-PrettyPrint: 1' -H 'Content-Type: text/csv' --data-binary '@<file absolute path>' '<public site URL>/services/apexrest/api/FileUpload/'