How can I read the request posted file in IIS module?

0

I wrote an IIS module and it's working fine. I want to get the posted file from request.

In below code, I could get sent form data and view the file in header:

IHttpRequest * pHttpRequest = pHttpContext->GetRequest();
if (pHttpRequest != NULL)
{
    LPCSTR body;
    DWORD cbBytesReceived = 1024;
    void * pvRequestBody = pHttpContext->AllocateRequestMemory(cbBytesReceived);

    if (NULL == pvRequestBody)
    {
        pProvider->SetErrorStatus(hr);
        return RQ_NOTIFICATION_FINISH_REQUEST;
    }

    if (pHttpRequest->GetRemainingEntityBytes() > 0)
    {
        while (pHttpRequest->GetRemainingEntityBytes() != 0)
        {
            hr = pHttpRequest->ReadEntityBody(
                pvRequestBody, cbBytesReceived, false, &cbBytesReceived, NULL);
            if (FAILED(hr))
            {
                if (ERROR_HANDLE_EOF != (hr & 0x0000FFFF))
                {
                    pProvider->SetErrorStatus(hr);
                    return RQ_NOTIFICATION_FINISH_REQUEST;
                }
            }

            body = (LPCSTR)pvRequestBody;
            pszResult = pszResult + body;
        }
    }
}

The result is:

-----------------------5r707ac9a9687yu

Content-Disposition: form-data; name="file"; filename="1.zip"

Content-Type: application/octet-stream

PKþóÐMš`_ÿív(X[úM/­xvœ5a¢~¯²²ÊÆÎÈá"}å
lIœì*7·®-W§Xþn¹DçvÃŒØÀ>ÊHñ\N-kÂ¥ûºÂm'ŒäõÚÌŸÏŽ)ããSqŽT3ÕïDñ?ËWÇKy«zAÉ÷øŒ¿ÂÇ   

I tried to cast file part(PKþóÐMš`_ÿív ...) to binary and write file, but file is curropted because the header contains all info (all posted files,content denposition,...) and not the clear binary file.

How can I write the sent files on disk(binary/text)?

c
iis-modules
asked on Stack Overflow Jan 13, 2020 by user5674 • edited Jan 13, 2020 by Anirban166

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0