Fledge
An open source edge computing platform for industrial users
All Classes Functions Variables Pages
form_data.h
1 #ifndef _FORM_DATA_H
2 #define _FORM_DATA_H
3 /*
4  * Fledge utilities functions for handling HTTP form data upload
5  * with multipart data
6  *
7  * Copyright (c) 2022 Dianomic Systems
8  *
9  * Released under the Apache 2.0 Licence
10  *
11  * Author: Massimiliano Pinto
12  */
13 
14 #include <logger.h>
15 #include <server_http.hpp>
16 
17 #define CR '\r'
18 #define LF '\n'
19 
32 class FormData {
33  public:
34  class FieldValue {
35  public:
36  FieldValue()
37  {
38  size = 0;
39  start = NULL;
40  };
41  const uint8_t* start;
42  size_t size;
43  std::string filename;
44  };
45 
46  public:
47  FormData(std::shared_ptr<SimpleWeb::Server<SimpleWeb::HTTP>::Request> request);
48  void getUploadedData(const std::string& field, FieldValue& data);
49  void getUploadedFile(const std::string& field, FieldValue& data);
50  bool saveFile(FieldValue& b, const std::string& fileName);
51 
52  private:
53  uint8_t* skipSeparator(uint8_t *b);
54  uint8_t* skipDoubleSeparator(uint8_t *b);
55  uint8_t* getContentEnd(uint8_t *b);
56  uint8_t* findDataFormField(uint8_t* buffer, const std::string& field);
57 
58  private:
59  const uint8_t* m_buffer; // pointer to already allocated buffer data
60  size_t m_size; // buffer size
61  std::string m_boundary; // multipart boundary
62 };
63 #endif
void getUploadedData(const std::string &field, FieldValue &data)
Fetch content data uploaded without file, example curl -v -v -v –output - -X POST -F &#39;attributes={"n...
Definition: form_data.cpp:232
bool saveFile(FieldValue &b, const std::string &fileName)
Save the uploaded file.
Definition: form_data.cpp:373
Definition: form_data.h:34
This class represents a parsed HTTP form data uploaded to SimpleWeb::Server<SimpleWeb::HTTP.
Definition: form_data.h:32
void getUploadedFile(const std::string &field, FieldValue &data)
Fetch content data uploaded as file, example curl -v -v -v –output - -X POST -F "bucket=@/some_path/...
Definition: form_data.cpp:282