| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | ||||
| 4 | 5 | 6 | 7 | 8 | 9 | 10 |
| 11 | 12 | 13 | 14 | 15 | 16 | 17 |
| 18 | 19 | 20 | 21 | 22 | 23 | 24 |
| 25 | 26 | 27 | 28 | 29 | 30 | 31 |
Tags
- react DOM
- node
- yml
- react-hook-form
- xlsx
- API Gateway
- Route53
- react-xml-parser
- readableStream
- timeinput
- dynamodb
- 프로그래머스
- JavaScript
- react-sortable-hoc
- gitignore
- AWS
- signIn
- electron-builder
- react-admin
- zerocho
- window.postMessage
- electron
- domtoimage
- cognito
- TypeScript
- 가상 DOM
- react
- axios
- jimp
- icrawler
Archives
- Today
- Total
꾸준히 공부하는 개발자
[Node.js] url로 img Download 본문
이미지를 axios로 blob 데이터로 받아와
dom에 직접 image를 생성 후 그 dom을 클릭하여 a tag의 href를 클릭한 효과를 만들어 다운 받는다.
axios({
url: decodeURIComponent(url),
method: 'GET',
responseType: 'blob'
}).then((response) => {
const url = window.URL.createObjectURL(new Blob([response.data]))
const link = document.createElement('a')
link.href = url
link.setAttribute('download', `${item.id}.jpg`)
document.body.appendChild(link)
link.click()
})
p.s cors 문제가 일어난다면 요즘 사용하는 SPA 프레임워크 프론트엔드(react,vue 등...)에서는 처리할 수 없다.
'Node.js' 카테고리의 다른 글
| [Node.js] XML Parser (0) | 2019.12.20 |
|---|---|
| [Node.js] ReadableStream 을 이용한 dblp.xml 파일 받아오기 (0) | 2019.12.20 |
| [Node.js] bluebird.js Promise (concurrency) (0) | 2019.12.18 |
| [Node.js] Jimp crop을 이용하여, 사진 자르기 (0) | 2019.11.19 |
| [Node.js] Jimp 이용하여 비율에 맞게 resize (0) | 2019.11.18 |
Comments