Overview
Features
Download
Documentation
Community
Add-Ons & Services

question of processing silverlight file upload

A general discussion forum.

question of processing silverlight file upload

Postby kakamatyi » 10 Jan 2011, 21:57

Hi all,

I would like to process silverlight file upload. The popular upload mechanisms don't use form upload but chunk uploads, like this sample here:
http://www.c-sharpcorner.com/UploadFile ... light.aspx

How to handle the uploaded chunks?

The httpformserver example does not handle the upload, please show me the right way...

Thanks,
Kaka
kakamatyi
 
Posts: 9
Joined: 22 Nov 2009, 12:00

Re: question of processing silverlight file upload

Postby guenter » 11 Jan 2011, 11:58

I'm guessing here that Silverlight (in your case) simply sends a POST request with the file in the request body (using chunked transfer encoding).
To handle this, create a new Poco::Net::HTTPRequestHandler subclass that you create in your request handler factory for the file upload path.
The handleRequest() method should look as follows:

Code: Select all
void handleRequest(Poco::Net::HTTPServerRequest& request, Poco::Net::HTTPServerResponse& response)
{
    // do some checks here
    if (request.getMethod() == Poco::Net::HTTPRequest::HTTP_POST)
    {
        // copy request body containing uploaded file to a local file
        Poco::FileOutputStream ostr("uploaded_file.dat");
        Poco::StreamCopier::copyStream(request.stream(), ostr);
        response.setStatusAndReason(Poco::Net::HTTPResponse::HTTP_OK);
        response.send();
    }
    else
    {
        response.setStatusAndReason(Poco::Net::HTTPResponse::HTTP_BAD_REQUEST);
        response.send();
    }   
}
guenter
 
Posts: 1138
Joined: 11 Jul 2006, 16:27
Location: Austria

Re: question of processing silverlight file upload

Postby kakamatyi » 11 Jan 2011, 22:48

Thanks pal, this works like a charm!!!!

One more question: I can find the post params in the request.getURI(); - is there any elegant way to parse them into a NameValueCollection?

Thanks again!!!
kakamatyi
 
Posts: 9
Joined: 22 Nov 2009, 12:00

Re: question of processing silverlight file upload

Postby guenter » 11 Jan 2011, 23:12

There would be the Poco::Net::HTMLForm class that would do this. But in its current form it does not work for your case - if it detects a POST request it assumes that the form data is in the request body, whereas in your case the request data is in the query string. A workaround would be to create a subclass of Poco::Net::HTML form, with a constructor that takes a Poco::Net::HTTPRequest object and uses the (protected) readUrl() method to read the form parameters from the request URI. Something like:

Code: Select all
class SpecialHTMLForm: public Poco::Net::HTMLForm // stupid name, I know...
{
public:
    SpecialHTMLForm(const Poco::Net::HTTPRequest& request)
    {
        Poco::URI uri(request.getURI());
        std::istringstream istr(uri.getRawQuery());
        readUrl(istr);
    }
};
guenter
 
Posts: 1138
Joined: 11 Jul 2006, 16:27
Location: Austria

Re: question of processing silverlight file upload

Postby kakamatyi » 12 Jan 2011, 00:28

Excellent, thanks pal!
Great library and excellent support - a winner combination:)
kakamatyi
 
Posts: 9
Joined: 22 Nov 2009, 12:00


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 1 guest

cron