1
module FileUploadService = 

  type FileDetails() =
        member val fileName= string with get,set
        interface IRequiresRequestStream with
           member val RequestStream = null with get,set



  type FileService() = 
          inherit Service()
          interface IService
             member this.Post(request : FileDetails ) = 
               //My Logic
               //can not able to read "request.fileName" property value.

I am trying to create service using servicestack. RequestDTO has two property (fileName and RequestStream).

I am tring to read value of request.fileName property and it is showing value ctor@25. I don't understand why it is showing ctor@25 value every time.

EDIT- Below code is written at Client side.

    function uploadBlobOrFile(fileData) {
        var xhr = new XMLHttpRequest();
        xhr.open('POST', "http://172.27.15.26:8000/ById/FileUploadService", true);

        xhr.withCredentials=true;
        xhr.onload = function (e) {
            progressBar.value = 0;
            progressBar.textContent = progressBar.value;
        };
        xhr.onreadystatechange = function () {
            if (xhr.readyState == 4 && xhr.status == 200) {
                console.log("success");
            }
        };
        var data = new FormData();
        data.append("fileName", "FileName.txt"); 
        data.append("RequestStream", file);

        xhr.send(data);
    }

chirag
  • 1,818
  • 1
  • 15
  • 36
  • 1
    This excludes the most important part of this question, the client code or raw HTTP that made the request. – mythz Aug 21 '15 at 14:57
  • please check my updated question. – chirag Aug 21 '15 at 15:24
  • It looks like you're sending a `multipart/form-data` request not a raw stream of bytes so don't use `IRequiresRequestStream`, use `base.Request.Files` instead. Also `RequestStream` is not a normal property, it represents the entire HTTP Request body as a stream of bytes, i.e. not a single FormData property that your javascript assumes. – mythz Aug 21 '15 at 15:36

1 Answers1

1

When you decorate your Request DTO with IRequiresRequestStream you're telling ServiceStack not to read the Request Body as you're taking over deserializing the Request Stream yourself. However it will still try to populate the Request DTO with the rest of the Request parameters that were submitted with the Request.

Without seeing the actual HTTP Request I can't tell if fileName is also included as part of the HTTP Request but if this is a multipart/formdata request the fileName is included in the HTTP Headers.

But if it is a multipart/formdata Request DO NOT use IRequiresRequestStream to read the request. IRequiresRequestStream only makes sense if a raw stream of bytes was posted to the URL, it's not for processing multipart/formdata which should use base.Request.Files which is specifically for processing multipart/formdata requests and includes access to additional metadata posted with the File Upload.

Community
  • 1
  • 1
mythz
  • 141,670
  • 29
  • 246
  • 390