drogon icon indicating copy to clipboard operation
drogon copied to clipboard

How to allow seeking of download video file ?

Open Rz-Rz opened this issue 9 months ago • 1 comments

I am serving mp4 video files from Drogon like this :

  drogon::app().registerHandler(
      "/static/{1}",
      [](const drogon::HttpRequestPtr &req,
         std::function<void(const drogon::HttpResponsePtr &)> &&cb,
         std::string fileName) {
        auto filePath = "./" + fileName;
        auto resp = drogon::HttpResponse::newFileResponse(filePath);
        cb(resp);
      });

The problem is I cannot seek forward or backward (except for the very beginning) of the video file. If I want to fast forward to 30 seconds I need to wait that the video plays.

Rz-Rz avatar Feb 19 '25 16:02 Rz-Rz

Drogon supports range responses, you can try it:

    static HttpResponsePtr newFileResponse(
        const std::string &fullPath,
        size_t offset,
        size_t length,
        bool setContentRange = true,
        const std::string &attachmentFileName = "",
        ContentType type = CT_NONE,
        const std::string &typeString = "",
        const HttpRequestPtr &req = HttpRequestPtr());

an-tao avatar Feb 20 '25 02:02 an-tao