Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

karthik_dev's avatar

How to download a file from a blob url

I'm getting a preview link or blob link from the frontend(reactjs).I tried many ways to download the file using "blob:http://localhost:3000/6abc903f-e38c-4ad0-9b68-87d05314f76f"

          $content = file_get_contents($modelfilepath); // URL of your blob object
         file_put_contents('/my/folder/flower.jpg', $content);`
Also tried with curl but not able to download and save the file in the server.

$str = $request->values['modelfile']; $modelfilepath= trim($str,"blob:"); $ch = curl_init($_GET[$str]); $fp = fopen('C:\xampp\test', 'wb'); curl_setopt($ch, CURLOPT_FILE, $fp); curl_setopt($ch, CURLOPT_HEADER, 0); curl_exec($ch); curl_close($ch); fclose($fp);

Please help me to solve this issue.
0 likes
3 replies
shez1983's avatar

is this file supposed to be downloaded code or show you a 'pop up telling you to open/save the file as you normally get on sites' ?

if its the later one then you can use Response::download($url).. if its the first one then you should be able to read the contents and save them in your storage

pj-lav's avatar

I faced the same problem. But cannot found the solution here, so would like to post for sharing my solution. I have read somewhere and it said you cannot use access from the server. I do like below and can send pictures to backend.

  1. Get the blob URL where you store and get it from where you store the file in. In my case, I have the class img-preview (show a preview of image) where I can get the blobs URLs via it attribute. I store file info in FILES variables. I will send pictures[] to backend retrieve the files and store it. So I do like this, const imgs = document.querySelectorAll(".img-preview"); const fd = new FormData(); for (var x = 0; x < imgs.length; x++) { fd.append("pictures[]", FILES[imgs[x].currentSrc]); }

  2. You add it as a formData object and send it via ajax. (I could not do it via general form submit) $.ajax({ type: 'POST', url: uri, cache: false, contentType: false, processData: false, data : fd, success: function(data){ console.log(data) }, error: function(err){ console.log(err); } }) Do not forget to add "_token" in above request like this. fd.append('_token','{{csrf_token()}}')

Then in backend you can run a loop to retrieve all the files.

Hope this help.

Please or to participate in this conversation.