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

Feature/http multipart post (file upload to sming webserver) #690

Conversation

patrickjahns
Copy link
Member

This is the first "fully" working implementaiton for file-uploading/http-multipart-post for http server. (#552)

Currently it provides functionality to:

  • upload single files
  • upload multiple files at once
  • upload files with additional vars

To enable uploading for a certain path, a delegate has to be provided:
void addPath(String path, HttpPathDelegate callback, HttpUploadDelegate uploadcallback);

The uploadcallback function is defined as following:

void functionName(HttpRequest&, HttpUpload&)

The function has thus access to the current request in the sense of all Header and Query Paramters (as well as path) can be accessed to decide if we accept the upload (or not)

In the pathdelegate information about the uploaded files is accessible by calling:

if(request.hasUpload()) {
    Vector<HttpUpload*> uploads = request.getUploads();
}

HttpUpload is defined as

struct HttpUpload {
    String filename;
    String name;
    String type;
    size_t totalSize;
    size_t curSize; // size of the current data block
    char* bufferdata; //pointer to the data
    file_t file;
    HttpUploadStatus status;
};

after a successfull upload curSize and bufferdata will be NULL and not accessible anymore (to avoid tampering with it
type contains the content-type field values
name is the variable name defined in the form field

If we receive a http-multipart-request without a filename or if the filename is empty - the data will be treated as normal http-post parameters and is accessible via getPostParameter - the limit NETWORK_MAX_HTTP_PARSING_LEN applies to all data that is not a file.

For testing see the working examples in samples/HttpServer_Upload

Please test it thoroughly and provide feedback. If you encounter any issues, it would be great if you document what has lead to the issue and provide a debug log.

Do you have any suggestion/remarks?

Known limitations/issues:

  • when providing a filename but no content - a file with the filename but 0 size will be created
    (it seems that chrome sends the header again when one presses go-back to the fileupload page)
  • max lenght for filenames is 31chars (current spiffs setting)
    how should we handle this use case? how to inform the user - automatically or should the "user of the framework" take care of this in the callback?

default file upload methods

fix memory leak

remove unecessary double parsing

small code cleanup

add Handler methods, code cleanup and bug fixing
@patrickjahns patrickjahns merged commit a5ffdae into SmingHub:Feature_HttpPost Apr 12, 2016
@patrickjahns
Copy link
Member Author

For discussions of the feature please provide feedback/thoughts in #694

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

Successfully merging this pull request may close these issues.

1 participant