I am using Spray-can to host a REST service to which a user will be able to upload a file. The block of code that listens for incoming requests is given below:
def receive: Receive = {
case _: Http.Connected => sender ! Http.Register(self)
case req@HttpRequest(HttpMethods.POST, Uri.Path("/upload"), headers, entity, _) =>
logger.info("Received file upload request.")
// Process the uploaded data using the 'entity' object
I upload the file using this curl command:
curl --data-binary @inputFile.csv 'devserver:8998/upload?tenant=DressShop&facility=CityCenter&customer=Jimmy'
The challenge I am facing is that I'm not able to pick up the filename "inputFile.csv" from the request, though I'm getting the data from the "entity" object. I tried poring through the API but couldn't find out any way to get the filename.
My objective is to ensure that I allow upload of only csv files.