0

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?

5
  • Why not use PHP to handle the upload? Then the PHP script can call your C++. – moonman239 Jun 24 at 19:01
  • Can you explain a little more how this might work? I'm not great with PHP. – psOneOneOne Jun 24 at 19:06
  • What does the value of theBlobURL actually look like? If it does not begin with http: or https: then traditional HTTP libraries will not be able to access it. Sounds like theBlobURL contains a URL that is private to the browser, so only the browser can access its content – Remy Lebeau Jun 24 at 19:28
  • @psOneOneOne first, the client sends the server the URI of the file to be uploaded, then in PHP you use something like move_uploaded_file($_FILE['(the form field of the file)'],"(a new path for the file)") and then you can have the C++ program reference the file at that new location. – moonman239 Jun 24 at 19:54
  • @moonman239 but the URI of the file to be uploaded is the root problem. When user drops or selects a file in JS, I cannot see the file path, I only have the resulting file. This is why I was using Blob URL to begin with. – psOneOneOne Jun 24 at 20:00
0

Remy Lebeau was correct, the Blob URL is private to the browser. It cannot be downloaded outside the browser.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.