I have an Angular front end with a C++ powered back end. I want the C++ back end to grab a file from a blob URL created by the front end (with URL.CreateObjectURL).
I have tried using URLDownloadToFile:
HRESULT hr = URLDownloadToFile(NULL, theBlobURL, outfilename, 0, NULL);
As well as curl:
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);
}
Both of these methods work with a traditional file URL (I tested with this public file), but fail with my blob URL. URLDownloadToFile gives "the specified protocol is unknown" as the HRESULT and curl saus "CURLE_COULDNT_RESOLVE_HOST".
I've confirmed via the browser that the blob URL is still available at the time I am trying to open it.
Do I need to do anything different to get a blob?
Remy Lebeau was correct, the Blob URL is private to the browser. It cannot be downloaded outside the browser.