file_upload_task.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. #pragma once
  2. #include <map>
  3. #include <string>
  4. #include "Poco/Foundation.h"
  5. #include "Poco/Runnable.h"
  6. #include "request/object_req.h"
  7. #include "trsf/transfer_handler.h"
  8. namespace qcloud_cos {
  9. class FileUploadTask : public Poco::Runnable {
  10. public:
  11. FileUploadTask(const std::string& full_url, uint64_t conn_timeout_in_ms,
  12. uint64_t recv_timeout_in_ms, unsigned char* pbuf = NULL,
  13. const size_t data_len = 0,
  14. bool verify_cert = true,
  15. const std::string& ca_location = "");
  16. FileUploadTask(const std::string& full_url,
  17. const std::map<std::string, std::string>& headers,
  18. const std::map<std::string, std::string>& params,
  19. uint64_t conn_timeout_in_ms, uint64_t recv_timeout_in_ms,
  20. const SharedTransferHandler& handler,
  21. bool verify_cert = true,
  22. const std::string& ca_location = "");
  23. FileUploadTask(const std::string& full_url,
  24. const std::map<std::string, std::string>& headers,
  25. const std::map<std::string, std::string>& params,
  26. uint64_t conn_timeout_in_ms, uint64_t recv_timeout_in_ms,
  27. unsigned char* pbuf = NULL, const size_t data_len = 0,
  28. bool verify_cert = true,
  29. const std::string& ca_location = "");
  30. ~FileUploadTask() {}
  31. void run();
  32. void UploadTask();
  33. void SetUploadBuf(unsigned char* pdatabuf, size_t data_len);
  34. std::string GetTaskResp() const;
  35. bool IsTaskSuccess() const;
  36. void SetTaskSuccess() { m_is_task_success = true; }
  37. int GetHttpStatus() const;
  38. std::map<std::string, std::string> GetRespHeaders() const;
  39. void AddParams(const std::map<std::string, std::string>& params);
  40. void SetParams(const std::map<std::string, std::string>& params);
  41. void AddHeaders(const std::map<std::string, std::string>& headers);
  42. void SetHeaders(const std::map<std::string, std::string>& headers);
  43. std::string GetErrMsg() const { return m_err_msg; }
  44. void SetResume(const bool is_resume) { m_is_resume = is_resume; }
  45. bool IsResume() const { return m_is_resume; }
  46. void SetResumeEtag(const std::string& etag) { m_resume_etag = etag; }
  47. std::string GetResumeEtag() const { return m_resume_etag; }
  48. void SetPartNumber(uint64_t part_number);
  49. uint64_t GetPartNumber() const { return m_part_number; }
  50. void SetVerifyCert(bool verify_cert);
  51. void SetCaLocation(const std::string& ca_location);
  52. private:
  53. std::string m_full_url;
  54. std::map<std::string, std::string> m_headers;
  55. std::map<std::string, std::string> m_params;
  56. uint64_t m_conn_timeout_in_ms;
  57. uint64_t m_recv_timeout_in_ms;
  58. unsigned char* m_data_buf_ptr;
  59. size_t m_data_len;
  60. std::string m_resp;
  61. bool m_is_task_success;
  62. int m_http_status;
  63. std::map<std::string, std::string> m_resp_headers;
  64. std::string m_err_msg;
  65. bool m_is_resume;
  66. std::string m_resume_etag;
  67. uint64_t m_part_number;
  68. SharedTransferHandler m_handler;
  69. bool m_verify_cert;
  70. std::string m_ca_location;
  71. };
  72. } // namespace qcloud_cos