In this blog, I will explain that how can we handle multipart and non multipart request together.
It is not necessary that we will get only one type of request either multipart or non multipart all the time. We can get either both of two. So we have to handle both type of request.
If we will handle only one type of request then if another type of request will come then we will not be able to handle that and nothing will happen.
So here, I am explaining the way to handle both type of request in spray.
We are getting the request on this URL:
http://"server IP":"Port"/email
In above, first one is handling multipart request while second one is handling non multipart (application url encoded) request.
Now if we get multipart request then we should handle this request like this :
Below is the method which extract attachment detail :
Below method is used for generating UID for attachments name. because we can get same name attachment more than once. So to differentiate, we prepend UID to each attachment file name.
And, if we get non multipart request (application-url-encoded) then we should handle like this :