-
Notifications
You must be signed in to change notification settings - Fork 45
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
Feature request:upload handler #1
Comments
UPDATE:
|
Hi Is the form you are using to post the file good? (It has to be multipart) |
Thanks for your response. Request.cpp: ...
int Request::upload(string destination_dir)
{
return mg_upload(connection, destination_dir.c_str());
} Request.h ...
int upload(string destination_dir);
... upload.cpp #include <unistd.h>
#include <stdlib.h>
#include <signal.h>
#include <mongoose/Server.h>
#include <mongoose/WebController.h>
using namespace std;
using namespace Mongoose;
class MyController : public WebController
{
public:
void upload(Request &request, StreamResponse &response)
{
response << "Upload test begin " << endl;
response << "Number of file uploaded:" << request.upload(".") << endl;
}
void setup()
{
addRoute("POST", "/", MyController, upload);
}
};
int main()
{
MyController myController;
Server server(8080);
server.registerController(&myController);
server.start();
while(1)
sleep(10);
} Here is the output:
Any idea? |
Ok I guess this is because I systematically read all the post data in the request, so we'll have to change this behaviour to support post files |
Line 22 of (I cant work ok this since I am not near a computer now) |
Yes, you are right. |
Why not, but if we test the |
Since there are two ways to send data: ...
// Downloading send data
ostringstream sendData;
// if (method == "POST") {
const char * content_type = mg_get_header(connection, "Content-Type");
if (content_type!= NULL && strcmp(content_type, "application/x-www-form-urlencoded") == 0){
int
char post[
while (n = mg_read(connection, post, sizeof(post))) {
sendData.write(post, n);
}
}
data = sendData.str();
... Also I noticed that you request_info->http_headers array manually to get header, but mongoose.c already offered a convenient function: |
Hi, I have implemented the upload feature, including upload callback(same as you did for |
I still don't imagine what is the best way to put the file upload in the binding, I dont think the callback is really important, we could indeed have a method to save the uploaded file somewhere |
the mg_upload can decide the location. But If you don't have that call I still don't imagine what is the best way to put the file upload in the I dont think the callback is really important, we could indeed have a — |
You're right However, I'm not really happy with the way mongoose handle the naming of Allowing the conttoller developper to choose the name would be better,
|
If we want to rename the file, I think it's hard to handle multiple files in one request. |
Yes, we will have to use the callback Maybe we could create a method that call
|
But if we do that, then this project is no longer a just simple binding of mongoose. |
It's already more than that (think of sessions, controllers and routing for The goal is not just to wrap mongoose but to provide a developer-friendly Mongoose is tiny and compiles very fast, which makes it cool but using it We are not just providing a simple binding but also some additional helpers
|
Maybe I should change this repo description to something like "C++ web-application library based on mongoose" |
I've just commited a simple upload system I think we should now add possibilities for do things with uploaded files like move/rename them |
(see |
Thanks a lot. |
Hi,
Could you support
mg_upload
wrapper andcallbacks.upload
?The text was updated successfully, but these errors were encountered: