[Cppcms-users] Problem with http::file and the returned file name
Brought to you by:
artyom-beilis
|
From: Christian G. <chr...@gm...> - 2013-07-05 08:42:00
|
Hi all.
In my web application I make use of a file uploader, which works like
a charm. But
I run into this problem:
Some older IE versions (6,7,8) are sending the full path of the uploaded file
in the multipart data - verified via wireshark.
All other browsers (chrome, ff, safari) are sending only the filename.
This looks like:
Jul 5 10:24:51 chgm-pc tssw: Upload: request POST: id 'upload' (upload.cpp:21)
Jul 5 10:24:51 chgm-pc tssw: upload: storing file C:Dokumente und
EinstellungengmeinerEigene DateienDownloads01_257782.pdf - size:
2947635 (upload.cpp:41)
Jul 5 10:24:51 chgm-pc tssw: upload:
/tmp/If37354f45a5f672658789c3a33e95e68/C:Dokumente und
EinstellungengmeinerEigene DateienDownloads01_257782.pdf
(upload.cpp:48)
I thought that I could filter out the substring starting from the last
\ in the filename, but cppcms filters away all \.
Is there a way to configure it or did I found a bug?
The file looks in wireshark like:
C:\Dokumente und Einstellungen\gmeiner\Eigene Dateien\Download\s01_257782.pdf
Here is my currently used uploader
if (id == "upload")
{
upload.form.load(context());
if (upload.form.validate())
{
std::string filename = upload.form.file.value()->filename();
// some versions of the Internet Explorer send the
full path as filename
// and so we need to do some post processing in oder
to only get the filename.
unsigned int found = filename.rfind("\\");
if (found != std::string::npos)
{
BOOSTER_DEBUG("Upload") << "found @ " << found;
filename = filename.substr(found);
}
BOOSTER_DEBUG("upload") << "storing file "
<< filename
<< " - size: " << upload.form.file.value()->size();
// store file in users tmp folder
std::string root = session().get("tmp");
upload.form.file.value()->save_to(root + filename);
BOOSTER_DEBUG("upload") << root + filename;
// TODO: return information's about uploaded file
this->empty_json_response();
}
else
{
BOOSTER_ERROR("upload") << "data not valid";
response().make_error_response(cppcms::http::response::not_acceptable);
}
}
thanks
--
Christian Gmeiner, MSc
|