chirag
chirag

Reputation: 1828

Property of RequestDTO is giving wrong value in servicestack

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);
    }

Upvotes: 1

Views: 75

Answers (1)

mythz
mythz

Reputation: 143399

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.

Upvotes: 1

Related Questions