Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/dart/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用Axios和React下载并操作svg文件_Javascript_Reactjs_Axios - Fatal编程技术网

Javascript 使用Axios和React下载并操作svg文件

Javascript 使用Axios和React下载并操作svg文件,javascript,reactjs,axios,Javascript,Reactjs,Axios,我想下载到服务器,然后在我的应用程序中使用svg图像,使用axios作为后端,使用React作为前端。我在服务器端编写了以下函数,可以下载文件: consthttps=require('https'); 常数fs=要求('fs'); const downloader=(url,文件名)=>{ https.get(url,函数(res){ const fileStream=fs.createWriteStream(文件名); res.pipe(文件流); fileStream.on('finish

我想下载到服务器,然后在我的应用程序中使用svg图像,使用axios作为后端,使用React作为前端。我在服务器端编写了以下函数,可以下载文件:

consthttps=require('https');
常数fs=要求('fs');
const downloader=(url,文件名)=>{
https.get(url,函数(res){
const fileStream=fs.createWriteStream(文件名);
res.pipe(文件流);
fileStream.on('finish',function()){
fileStream.close();
console.log('done');
})
})
};
下载程序('https://www.humdes.com/local/tools/svg/?TYPE=calculation&KEY=proektor_1_3_b779c57622ad9891313a6046c1604cea“,”file.svg')
问题是,我现在不知道如何将它连接到我的前端。比如说,我想创建一个在ComponentDidUpdate中运行的函数:

downloader(this.state.imagesource,this.state.filename){
//???
}
此函数必须使用url和文件名下载文件。但我必须在downloader函数中写些什么才能使它与我的axios函数一起工作呢?之后我如何访问下载的文件,比如说,从svg中删除一些元素,然后将其余的作为图像插入到我的组件中?

下载文件(){
获取(“/yourrul”)
.然后((res)=>res.blob())
.然后((blob)=>{
让url=url.createObjectURL(blob);
设pom=document.createElement('a');
pom.setAttribute('href',url)
setAttribute('download','yourfilename.extension');
pom.click();//这将下载文件
})

}
tnx,但这不是我所需要的。我希望图像存储在服务器上,而不是由用户下载