0

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/'
0

Well, you can upload the csv as Content Version, by making a post request using REST api to this particular url "/services/data/v45.0/sobjects/ContentVersion", and have a trigger for Content version object and call your particular class in that trigger to process the csv.

here is the link for your reference

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.