Skip to content
This repository was archived by the owner on Jan 20, 2025. It is now read-only.
This repository was archived by the owner on Jan 20, 2025. It is now read-only.

Document how to use handleUpload and handleBody depending on what client sends #190

@probonopd

Description

@probonopd

EDIT: This may be of lesser priority if #191 can be solved.

Assume I have an API endpoint /api/files/local that can be called with or without FILE.

The documentation says:

//Check if POST (but not File) parameter exists
if(request->hasParam("download", true))
  AsyncWebParameter* p = request->getParam("download", true);

//Check if FILE was uploaded
if(request->hasParam("download", true, true))
  AsyncWebParameter* p = request->getParam("download", true, true);

But the documentation does not say how to handle these two cases.

Consider this code:

  server.on("/api/files/local", HTTP_POST, [](AsyncWebServerRequest * request) {
    if(!request->hasParam("file", true, true)){
      // Need handleBody?
      // To call handleBody instead of handleUpload, we need a filter since we can only hardwire one handler to server.on. How to do this?
    }
    request->send(200, "application/json", "{}");
  }, handleUpload);

How can I make the upload work with handleUpload or handleBody depending on what the client sends?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions