Re: Uploading Binary files to HTTPS



"Igor Tandetnik" <itandetnik@xxxxxxxx> wrote in message
news:OJB4LOcbIHA.4196@xxxxxxxxxxxxxxxxxxxxxxx
Show the code where you call IWinHttpRequest::Send. My guess is, you are
doing something that causes the content to be terminated by the first zero
byte, e.g. handling a BSTR carelessly.

Ok, I posted the code at the bottom.. I got it to a point it doesn't cut
off the file content, however it's as if the web server or the ASPUpload
doesn't know what to do with it.. I cut out a lot of the content below,
because it's binary, but left the header and what's wrapped around the
binary file.. Does this data look right?
--------------------------------------
POST /DER/upload.asp HTTP/1.1
Cache-Control: no-cache
Content-Type: multipart/form-data; boundary=Xu02=$; Charset=UTF-8
Content-Length: 2249
Accept: */*
User-Agent: Mozilla/4.0 (compatible; Win32; WinHttp.WinHttpRequest.5)
Host: 209.163.160.61:5000
Connection: Keep-Alive

--Xu02=$
Content-Type: application/octet-stream
Content-Disposition: multipart/form-data; name="PostData";
filename="1234567890.zip"
Content-Length: 1234

PKzX)????iI/F@
Q??????(}lxsPK 

--Xu02=$
--------------------------------------




Code:
--------------------------------------
ifstream infile (szFileName.c_str(), ios::in|ios::binary);
if(!infile)
{
if (pIWinHttpRequest) {
pIWinHttpRequest->Release();
pIWinHttpRequest = NULL;
}
*sContents = "ERROR: No file found to upload";
} else {
//get file size
struct _stat buf;
_stat(szFileName.c_str(), &buf);
int iFileSize = buf.st_size;
char pHeaderInfo[1024] = {0};

sprintf(pHeaderInfo, "%d", iFileSize);

//declare
int iHeaderSize = 0;
char* pszFile = (char*)szFileName.c_str();
string szHeader = "";
char* strInput = new char[MAX_READ];

//get file name from file passed in
int iSize = szFileName.length();
int iLoc = szFileName.find_last_of("\\")+1;
iSize -= iLoc;
memcpy(pszFile, &pszFile[iLoc], iSize);
pszFile[iSize]=0;

//create the header
szHeader.append("--Xu02=$\r\n");
szHeader.append("Content-Type: application/octet-stream\r\n");
szHeader.append("Content-Disposition: multipart/form-data;
name=\"PostData\"; filename=\"");
szHeader.append(pszFile);
szHeader.append("\"\r\n");
szHeader.append("Content-Length: ");
szHeader.append(pHeaderInfo);
szHeader.append("\r\n\r\n");

CComBSTR bstrBody = SysAllocString(T2OLE(szHeader.c_str()));

//load file into array
while(!infile.eof())
{
memset(strInput, 0, MAX_READ);
infile.read(strInput, MAX_READ);

unsigned int iBytesRead = 0;
iBytesRead = infile.gcount();

bstrBody.Append(strInput);
}

bstrBody.Append("\r\n\r\n--Xu02=$\r\n");

//close file
infile.close();

//copy to a format Send understands
_bstr_t bBody = bstrBody;

//send data
hr = pIWinHttpRequest->Send(bBody);

delete[] strInput;
}
--------------------------------------


.



Relevant Pages

  • Re: Uploading Binary files to HTTPS
    ... Chizl wrote: ... first zero byte, e.g. handling a BSTR carelessly. ... what's wrapped around the binary file.. ...
    (microsoft.public.vc.language)
  • Re: Very strange problem using FWRITE() to write data to a binary file
    ... > I'm facing a very very strange problem with a very very simple C ... > My goal should be to write to a binary file some numbers, ... > I made this stupid trial code: ... the broken "Reply" link at the bottom of the article. ...
    (comp.lang.c)
  • Re: Structure size and binary format
    ... And then I'm using this as a record for a binary file. ... the conversion mechanisms. ... Far and away the most portable transportation mechanism is pure ... the broken "Reply" link at the bottom of the article. ...
    (comp.lang.c)
  • Re: Replacing characters in file
    ... time to stop treating it as a text file but start handling it as a ... As I said it's a .DAT file ... Well, if it is not a text file but a binary file, then it isn't very ... meaningful to talk about characters. ...
    (comp.lang.perl.misc)

Loading