Discussion Board
File upload example using HTTP Client API???
2004-09-10, 17:45
#1
Registered User
Does anyone have (or know of) and example showing how to upload a file (eg. image) from a handset to a server using the new HTTP Client API?
Registered User
The HTTP client example has upload capabilities, just search for HTTP Client Example v1.0 in Forum Nokia.
Registered User
Thank you for your reply. I did find that example and it did provide a little help. However, my situation required that I send both textual (i.e. form-type) data as well as an image file. I resolved the issue by sending everything along as a multipart form.
Registered User
hi,
how did u build the multipart data request..
I am sending image binary data in Post body, & using content-type as image/jpeg.
only partial image is sent using the code below.
Below is the code on the phone:
void CIapAppView::PublishImageL()
{
_LIT(KAttachmentFileName, "Image.jpg");
//open image from images folder
TFileName path = PathInfo::PhoneMemoryRootPath(); //Default
path.Append( PathInfo::ImagesPath() );
path.Append(KAttachmentFileName);
TInt err=0;
TRAP(err, AddToStatusWindowL(path));
if(err)
Panic(EIapView);
RFs fs;
User::LeaveIfError(fs.Connect());
RFile infile;
TInt val=infile.Open(fs,path,EFileShareExclusive|EFileRead);
if(val==KErrNone)
{
TInt file_size;
infile.Size(file_size);
HBufC8* bufImageData;
bufImageData = HBufC8::NewL(file_size);
if(bufImageData)
{
TBuf8<256> data8;
while(ETrue)
{
if(infile.Read(data8)!=KErrNone)
{
TRAP(err, AddToStatusWindowL(_L("Error: reading file")));
if(err)
Panic(EIapView);
infile.Close();
fs.Close();
return;
}
if(data8.Length()==0) //eof
{
TRAP(err, AddToStatusWindowL(_L("Success: reading file")));
if(err)
Panic(EIapView);
iClient->CancelTransaction();
//use bufImageData to send http post
TBuf8<256> uri8;
//external public ip
_LIT8(url1, "http://61.246.187.164/Push2Publish/Image?imageName=myimage&identityID=11");
//internal public ip
//_LIT8(url1, "http://192.168.102.11/Push2Publish/Image?imageName=myimage&identityID=11");
//nitins ip
//_LIT8(url1, "http://192.168.5.67:8080/Push2Publish/Image?imageName=myimage&identityID=11");
uri8.Append(url1);
TPtr8 ptr_bufImageData=bufImageData->Des();
iClient->IssueHTTPPostL(uri8, _L8("image/jpeg"), ptr_bufImageData);
break;
}
TPtr8 ptr_bufImageData=bufImageData->Des();
ptr_bufImageData.Append(data8);
}
}
else
{
TRAP(err, AddToStatusWindowL(_L("Error: Allocating HBuf")));
if(err)
Panic(EIapView);
}
}
infile.Close();
fs.Close();
}
Thanks
Nitin
Posting Permissions
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
Forum Rules