Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6228913
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T09:28:16+00:00 2026-05-24T09:28:16+00:00

So I try such code: std::ofstream myfile; myfile.open (example.txt, std::ios_base::app ); myfile << Request

  • 0

So I try such code:

std::ofstream myfile;
myfile.open ("example.txt", std::ios_base::app );
myfile  << "Request body: " << request->body << std::endl << "Request size: " <<  request->body.length() << std::endl;

size_t  found_file = request->body.find("filename=");
if (found_file != std::string::npos)
{
    size_t  end_of_file_name = request->body.find("\"",found_file + 1);
    if (end_of_file_name != std::string::npos)
    {
        std::string filename(request->body, found_file+10, end_of_file_name - found_file);
        myfile << "Filename == " <<   filename << std::endl;
    }
}
myfile.close();

But it outputs in for example:

Request body: ------WebKitFormBoundary0tbfYpUAzAlgztXL

Content-Disposition: form-data; name="datafile"; filename="Torrent downloaded from Demonoid.com.txt"

Content-Type: text/plain



Torrent downloaded from http://www.Demonoid.com

------WebKitFormBoundary0tbfYpUAzAlgztXL--


Request size: 265
Filename == Torrent d

This means that from filename="Torrent downloaded from Demonoid.com.txt" my cede returnes Torrent d as a file name while it should return Torrent downloaded from Demonoid.com.txt. How to fix my file upload http request filename parser?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T09:28:17+00:00Added an answer on May 24, 2026 at 9:28 am

    string::find returns the index of the first character in the search string. So it’s giving you the index of the f in filename= when you search for that.

    In the line

    size_t  end_of_file_name = request->body.find("\"",found_file + 1);
    

    You’ll have to change that to

    size_t  end_of_file_name = request->body.find("\"", found_file + 9 + 1); // 9 because that's the length of "filename=" and 1 to start at the character after the "
    

    Then change

    std::string filename(request->body, found_file+10, end_of_file_name - found_file);
    

    To

    std::string filename(request->body, found_file + 10, end_of_file_name - (found_file + 10));
    

    You might want to add another variable to quit having to add 10 all the time as well.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have such code (Python 2.5, GAE dev server): try: yt_service.UpgradeToSessionToken() // this line
Boost asio has such socket connect api . I have such simple code: try
I try such code: static float shift = 0.0; double amplitude = 1000000 *
i try to run such code $collection->group(array('goods_id'=>1, 'server_id'=>1), array('count' => 0, 'ip'=>'', 'date'=>''), 'function
In the disassembly there's such code: movl $0x6,-0x4(%rbp) I try to print the value
I have such code with 2 structures: #include <list> using namespace std; struct Connection;
Let's suppose we have such code: int x = 0; try { try {
When I try to make a very large boolean array using Java, such as:
We try to convert from string to Byte[] using the following Java code: String
I try Request.Form.Set(k, v) but it's throwing exception Collection is read-only

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.