C++ 从 blob URL 下载音频/视频文件?

时间:2021-06-24 19:00:00

标签: c++ curl bloburls

我有一个带有 C++ 驱动后端的 Angular 前端。我希望 C++ 后端从前端创建的 blob URL 中获取文件(使用 URL.CreateObjectURL)。

我尝试过使用 URLDownloadToFile:

HRESULT hr = URLDownloadToFile(NULL, theBlobURL, outfilename, 0, NULL);

以及卷曲:

                CURL* curl;
                FILE* fp;
                CURLcode res;

                curl = curl_easy_init();
                if (curl) {
                    fp = fopen(outfilename2, "wb");
                    curl_easy_setopt(curl, CURLOPT_URL, theBlobURL);
                    curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, NULL);
                    curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp);

                    res = curl_easy_perform(curl);
                    if (res != CURLE_OK)
                        fprintf(stderr, "curl_easy_perform() failed: %s\n",
                            curl_easy_strerror(res));

                    curl_easy_cleanup(curl);
                }

这两种方法都适用于传统文件 URL(我使用 this 公共文件进行了测试),但无法使用我的 blob URL。 URLDownloadToFile 将“指定的协议未知”作为 HRESULT 和 curl 提供“CURLE_COULDNT_RESOLVE_HOST”。

我已经通过浏览器确认在我尝试打开 blob URL 时它仍然可用。

我需要做任何不同的事情才能得到一个 blob 吗?

1 个答案:

答案 0 :(得分:0)

Remy Lebeau 是对的,Blob URL 是浏览器私有的。无法在浏览器外下载。