File Upload Using Post | developer.brewmp.com File Upload Using Post | developer.brewmp.com

Developer

File Upload Using Post

Forums:

Hi all,

I've read through the previous messages on how to post text data to the server. However, I want to upload a file to the server, which probably requires some additional steps.

In step 1, I use IFILE_Read to open the file and read it into a buffer (pFileData).
In step 2, I create an ISHELL instance and use PeekFromMemory as follows:

if (SUCCESS == ISHELL_CreateInstance(pme->a.m_pIShell, AEECLSID_SOURCEUTIL, (void **)&pisu))
{

ISOURCEUTIL_PeekFromMemory(pisu, pme->m_pszFormData, pme->m_nDataLength, 0, 0, &pme->m_pWebAction.pipPostData);

ISOURCEUTIL_Release(pisu);

In step 3, I set the callback and use IWEB_GetResponse, as follows:

CALLBACK_Init(&pme->m_pWebAction.cb, WebAction_GotResp, pwa);

IWEB_GetResponse(pme->m_pIWeb, (pme->m_pIWeb, &pme->m_pWebAction.piWResp,
&pme->m_pWebAction.cb,
"http://test.server.com/uploadexec.php",
WEBOPT_HANDLERDATA,
pme->m_pWebAction,
WEBOPT_HEADER, "X-Method: POST\r\n",
WEBOPT_METHOD, "POST",
WEBOPT_BODY, pme->m_pWebAction.pipPostData,
WEBOPT_CONTENTLENGTH, pme->m_nDataLength,
WEBOPT_END));

A request is actually being made and the callback is issued, but the server receives a GET, instead of a POST, with no file data. PLEASE HELP!

Thanks!

hai how r u , am sending the code go through that code , this is the working code to upload a file to server,you can upload a file of any size .
static int ti_g8_UploadDataToWebsite(ti_g8_sms_parser *ti_g8_pVars)
{
ISourceUtil *ti_g8_pISourceUtil=NULL;
int ti_g8_Flag=0;
int i=0,j=0;
void *ti_g8_pszFileBuffer = NULL;
FileInfo ti_g8_pFileInfo;
SPRINTF(ti_g8_pVars->ti_g8_szFullUrl, "http://%s/%s%s%s",
"172.31.57.182:8080/brew","filehandler?","filename=",ti_g8_pVars->ti_g8_ESAC_msg_struct.ti_g8_szFileName);
ti_g8_pVars->ti_g8_pIFile = IFILEMGR_OpenFile(ti_g8_pVars->ti_g8_pIFileMgr,
ti_g8_pVars->ti_g8_ESAC_msg_struct.ti_g8_szFileName, _OFM_READ);
IFILE_GetInfo(ti_g8_pVars->ti_g8_pIFile,&ti_g8_pFileInfo);
ti_g8_pszFileBuffer = MALLOC((int)ti_g8_pFileInfo.dwSize *
(sizeof(char) + 1));
IFILE_Read(ti_g8_pVars->ti_g8_pIFile, ti_g8_pszFileBuffer,
ti_g8_pFileInfo.dwSize);
ISHELL_CreateInstance(ti_g8_pVars->ti_g8_pIShell,AEECLSID_SOURCEUTIL, (void **)&ti_g8_pISourceUtil) ;
ISOURCEUTIL_PeekFromMemory(ti_g8_pISourceUtil,ti_g8_pszFileBuffer,ti_g8_pFileInfo.dwSize,0,0,&ti_g8_pVars->ti_g8_pIPeekData);
ISOURCEUTIL_Release(ti_g8_pISourceUtil);
CALLBACK_Init(&ti_g8_pVars->ti_g8_OpenWebConnectionCallbackStruct,
ti_g8_OpenConnectionCB, ti_g8_pVars);
if(ti_g8_pVars->ti_g8_pIPeekData)
{
IWEB_GetResponse(ti_g8_pVars->ti_g8_pIWeb,(ti_g8_pVars->ti_g8_pIWeb, &ti_g8_pVars->ti_g8_pIWebResponse,&ti_g8_pVars->ti_g8_OpenWebConnectionCallbackStruct
, ti_g8_pVars->ti_g8_szFullUrl,
WEBOPT_HANDLERDATA, ti_g8_pVars,
WEBOPT_HEADER, "X-Method: POST\r\n",
WEBOPT_METHOD, "POST",
WEBOPT_BODY, ti_g8_pVars->ti_g8_pIPeekData,
WEBOPT_CONTENTLENGTH, ti_g8_pFileInfo.dwSize,
WEBOPT_END));
}
ti_g8_DisplayMessage(ti_g8_pVars, " Message Posted to Server...");
IPEEK_Release(ti_g8_pVars->ti_g8_pIPeekData);
return TRUE;
}

hai how r u , am sending the code go through that code , this is the working code to upload a file to server,you can upload a file of any size .
static int ti_g8_UploadDataToWebsite(ti_g8_sms_parser *ti_g8_pVars)
{
ISourceUtil *ti_g8_pISourceUtil=NULL;
int ti_g8_Flag=0;
int i=0,j=0;
void *ti_g8_pszFileBuffer = NULL;
FileInfo ti_g8_pFileInfo;
SPRINTF(ti_g8_pVars->ti_g8_szFullUrl, "http://%s/%s%s%s",
"172.31.57.182:8080/brew","filehandler?","filename=",ti_g8_pVars->ti_g8_ESAC_msg_struct.ti_g8_szFileName);
ti_g8_pVars->ti_g8_pIFile = IFILEMGR_OpenFile(ti_g8_pVars->ti_g8_pIFileMgr,
ti_g8_pVars->ti_g8_ESAC_msg_struct.ti_g8_szFileName, _OFM_READ);
IFILE_GetInfo(ti_g8_pVars->ti_g8_pIFile,&ti_g8_pFileInfo);
ti_g8_pszFileBuffer = MALLOC((int)ti_g8_pFileInfo.dwSize *
(sizeof(char) + 1));
IFILE_Read(ti_g8_pVars->ti_g8_pIFile, ti_g8_pszFileBuffer,
ti_g8_pFileInfo.dwSize);
ISHELL_CreateInstance(ti_g8_pVars->ti_g8_pIShell,AEECLSID_SOURCEUTIL, (void **)&ti_g8_pISourceUtil) ;
ISOURCEUTIL_PeekFromMemory(ti_g8_pISourceUtil,ti_g8_pszFileBuffer,ti_g8_pFileInfo.dwSize,0,0,&ti_g8_pVars->ti_g8_pIPeekData);
ISOURCEUTIL_Release(ti_g8_pISourceUtil);
CALLBACK_Init(&ti_g8_pVars->ti_g8_OpenWebConnectionCallbackStruct,
ti_g8_OpenConnectionCB, ti_g8_pVars);
if(ti_g8_pVars->ti_g8_pIPeekData)
{
IWEB_GetResponse(ti_g8_pVars->ti_g8_pIWeb,(ti_g8_pVars->ti_g8_pIWeb, &ti_g8_pVars->ti_g8_pIWebResponse,&ti_g8_pVars->ti_g8_OpenWebConnectionCallbackStruct
, ti_g8_pVars->ti_g8_szFullUrl,
WEBOPT_HANDLERDATA, ti_g8_pVars,
WEBOPT_HEADER, "X-Method: POST\r\n",
WEBOPT_METHOD, "POST",
WEBOPT_BODY, ti_g8_pVars->ti_g8_pIPeekData,
WEBOPT_CONTENTLENGTH, ti_g8_pFileInfo.dwSize,
WEBOPT_END));
}
ti_g8_DisplayMessage(ti_g8_pVars, " Message Posted to Server...");
IPEEK_Release(ti_g8_pVars->ti_g8_pIPeekData);
return TRUE;
}

If the file is large, it'll crash since you're trying to read it entirely at once (and thus MALLOC may fail, returning a NULL pointer...)
Take a look at a simpler way at:
http://brewforums.qualcomm.com/showthread.php?t=2331&highlight=ifile+WEB...

If the file is large, it'll crash since you're trying to read it entirely at once (and thus MALLOC may fail, returning a NULL pointer...)
Take a look at a simpler way at:
http://brewforums.qualcomm.com/showthread.php?t=2331&highlight=ifile+WEB...

Hi All,
Thanks so much for the posts. You've helped me TREMENDOUSLY!
I'm now able to post files to the server. However I still have a problem with large files. If I try to upload a 220KB file, only ~58K actually gets sent up.
I'm using the SourceFromAStream function as someone suggested, with the IFile as an input. pipPostData is an ISource type.
ISOURCEUTIL_SourceFromAStream(pisu, (IAStream *)pIFile, &pwa->pipPostData);
Any ideas why the larger files might still be getting truncated?
Please let me know, and thanks again...

Hi All,
Thanks so much for the posts. You've helped me TREMENDOUSLY!
I'm now able to post files to the server. However I still have a problem with large files. If I try to upload a 220KB file, only ~58K actually gets sent up.
I'm using the SourceFromAStream function as someone suggested, with the IFile as an input. pipPostData is an ISource type.
ISOURCEUTIL_SourceFromAStream(pisu, (IAStream *)pIFile, &pwa->pipPostData);
Any ideas why the larger files might still be getting truncated?
Please let me know, and thanks again...

I have the same problem with uploading big files...
Actually, files with size less than 60kb is ok to upload by one call. Tested ( on motorola v3m ).
Now, I'm looking for solution too, if anyone knows, it would be cool if he/she share the information here.

I have the same problem with uploading big files...
Actually, files with size less than 60kb is ok to upload by one call. Tested ( on motorola v3m ).
Now, I'm looking for solution too, if anyone knows, it would be cool if he/she share the information here.