Developers

I am trying to upload a file with an Ajax call in a WebSharper project. Sending data as JSON worked for me, but I've had trouble sending it as FormData (which is necessary for file upload, if I understand correctly.) My latest effort (below) fails immediately with a NoFormatException. Thank you for your help.

Thank you for your answer! Unfortunately, I have not even figured out yet how to send text as FormData. My current source code fails with POST http://localhost:9000/upload 404 (Not Found) when I click the button and I don't really understand why. Thank you for helping me.

[<FormData>] is meant to be used directly on the endpoint, i.e. on EndPoint.Upload, and for data passed from <form> elements via action="..." (encoded as application/x-www-form-urlencoded or multipart/form-data).

In your case, you are posting to your /upload endpoint a simple JSON object, but you are trying to receive it as a record. Either add [<Json "xxxx">] on your endpoint, or use [<FormData "xxx">] there and submit to it via <form action="...">.

(Hi Rene - just a quick comment: please use the WebSharper Forums to comment further - FPish and these forums have a different format for storing content, and the old FPish-style markup is being retired in favor of markdown, the format used by the forums. Thanks!)