当我删除一个链接时,我有fetch函数:
fetch: (source, load, error, progress, abort, headers) => {
//progress(true, 0, 1024);
axios({
// headers: {'Access-Control-Expose-Headers': 'Content-Disposition'},
method: 'get',
url: 'fetch?url='+source,
onUploadProgress: (e) => {
// updating progress indicator
progress(true, e.loaded, e.total);
}
}).then(response => {
// passing the file id to Filepond
if (response.status === 200) {
let blob = new Blob([response.data],{
type: "application/pdf"
})
load(blob)
}
}).
catch((thrown) => {
if (axios.isCancel(thrown)) {
console.log('Request cancelled', thrown.message);
} else {
// handle error
error(error)
console.log(thrown)
}
})
},
字符串
Laravel端点:
public function fetch(Request $request)
{
$url = $request->url;
$headers = [
'Content-Type' => 'application/pdf',
];
return response()->stream(function () use ($url) {
$file = fopen($url, 'rb');
fpassthru($file);
fclose($file);
}, 200, $headers);
}
型
文件池中的大小似乎较大,实际大小为2.3M
的数据
的
在验证方面,我使用PdfParser来计算页面数,但却出现了一个错误。我怀疑是获取过程从外部链接中获取的PDF文件出现了某种畸形,本地上传的PDF文件工作正常。也许在获取中的Blob转换?Ant输入会有帮助。加载函数
load: (source, load, error, progress, abort, headers) => {
// Should get a file object from the URL here
// ...
console.log(source)
// Should call the progress method to update the progress to 100% before calling load
// (computable, loadedSize, totalSize)
//progress(true, 0, 1024);
// Should call the load method with a file object when done
load(source);
// Should expose an abort method so the request can be cancelled
return {
abort: () => {
// Let FilePond know the request has been cancelled
abort();
}
};
},
型
1条答案
按热度按时间fdbelqdn1#
在axios中,默认响应是JSON,因此将其更改为arrayBuffer
字符串
那就把它变成一个Blob
型
现在尺寸正确