【发布时间】:2019-10-27 20:05:05
【问题描述】:
我正在尝试将图像从 url 转换为可以在 javascript 中使用的 blob 文件,但我失败了,我该怎么做或者这甚至可能:
到目前为止,我已经这样做了:
// $request->location is the url to the file in this case an image
$img = file_get_contents($request->location);
$ch = curl_init();
// set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL, $request->location);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
// grab URL and pass it to the browser
$img = curl_exec($ch);
// close cURL resource, and free up system resources
curl_close($ch);
return $img;
我想返回该 blob 并将其附加到我的客户端/javascript 端的 FileReader 对象。
【问题讨论】:
-
为什么要加载图像两次?究竟是什么问题?你有错误吗?
-
Blob 的构造函数非常简单,developer.mozilla.org/en-US/docs/Web/API/Blob/Blob#Syntax - 那么您到底遇到了什么问题?
标签: javascript php laravel blob