Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to get multi-part form file from the http request? #28

Closed
tjliupeng opened this issue Sep 2, 2020 · 8 comments
Closed

How to get multi-part form file from the http request? #28

tjliupeng opened this issue Sep 2, 2020 · 8 comments

Comments

@tjliupeng
Copy link

Hi, guys,

I want to use the workflow to build a RESTful server which can receiver image file from client and do some AI works. As the title says, how to get multi-part form file from the http request? Can you share a code example?

Thanks!

@Barenboim
Copy link
Contributor

You means splitting query of URI? Like http://.../?a=1&b=2c=3...
Maybe URIParser will help you.

@tjliupeng
Copy link
Author

tjliupeng commented Sep 2, 2020

@Barenboim , URI Like http://.../?a=1&b=2c=3 is usually the query parameter in URL for GET method. What I mean is the file attachment in the http request. You can think about the scenario which an image file was sent to the server, and the server need to save the file.

@Barenboim
Copy link
Contributor

Barenboim commented Sep 2, 2020

Sorry, we don't parse multi-part form of http message automatically. So you may get the message body, and parse it by yourself.
Example:
void process(WFHttpTask *task)
{
const void *body;
size_t size;
task->get_req()->get_parsed_body(&body, &size);
// parse body here
...
}
get_parsed_body() is an method of protocol::HttpMessage。BTW, this interface does NOT decode chunk encoding, it returns the orginal http message body.

@Barenboim
Copy link
Contributor

To decode chunked body, you may use HttpUtil::decode_chunked_body in HttpUtil. Or use HttpChunkCursor to decode chunks with zero-copy.

holmes1412 added a commit that referenced this issue Jan 30, 2021
merge from sogou/workflow dev
@Barenboim
Copy link
Contributor

@Barenboim
Copy link
Contributor

@tjliupeng
Restful web framework based on workflow: https://github.com/wfrest/wfrest

@tjliupeng
Copy link
Author

Nice.

@Jamishon
Copy link

int state = task->get_state();

    if (state == WFT_STATE_SUCCESS)
    {
        protocol::HttpResponse* response = task->get_resp();

        const void* body;
        size_t len;

        response->get_parsed_body(&body, &len);

        char* resp_body = new char[len + 1];
        memset(resp_body, 0, len + 1);
}

I use the snap code above to the http Post response, response data is to much, but the maxmium len is always 380696, I use the tool Postman it return the all data, how can I get the rest data or there is a bug on the reponse data buffer .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants