1

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)?

user5674
  • 11
  • 2
  • Using `fopen`, `fwrite` etc.? – Jabberwocky Jan 13 '20 at 07:09
  • the header is contains all info(all files,content denposition,...) and not clear binary file,i tried to cast file part(PKþóÐMš`_ÿív ...) to binary and write file,but file is curropted – user5674 Jan 13 '20 at 08:19

0 Answers0