fetch-api

GET image from authenticated route

穿精又带淫゛_ 提交于 2021-01-04 04:31:53
问题 I have a working image-upload front/back-end code working. Now I would like to be able to GET the image from server after it is uploaded. The problem is that the images must be behind an authenticated route, where user has to pass jwt token in header or body. When i try to fetch the image like this: fetch(imageURL, { method: 'GET', headers: { 'x-access-token': localStorage.getItem('token') } I just get a Form object as the response: <img alt="Your pic" src="[object FormData]"> Would there be

GET image from authenticated route

倖福魔咒の 提交于 2021-01-04 04:31:32
问题 I have a working image-upload front/back-end code working. Now I would like to be able to GET the image from server after it is uploaded. The problem is that the images must be behind an authenticated route, where user has to pass jwt token in header or body. When i try to fetch the image like this: fetch(imageURL, { method: 'GET', headers: { 'x-access-token': localStorage.getItem('token') } I just get a Form object as the response: <img alt="Your pic" src="[object FormData]"> Would there be

GET image from authenticated route

吃可爱长大的小学妹 提交于 2021-01-04 04:28:25
问题 I have a working image-upload front/back-end code working. Now I would like to be able to GET the image from server after it is uploaded. The problem is that the images must be behind an authenticated route, where user has to pass jwt token in header or body. When i try to fetch the image like this: fetch(imageURL, { method: 'GET', headers: { 'x-access-token': localStorage.getItem('token') } I just get a Form object as the response: <img alt="Your pic" src="[object FormData]"> Would there be

fetch() call not returning any data

点点圈 提交于 2020-12-15 07:28:57
问题 I'm having a problem with my fetch() call not working correctly. I have a recursion method that calls itself within this function, but once it passes the if statement, the data itself is not being resolved to the .then() call below. I would like to keep the recursion method within this function. Because the system that this function is calling will change the data.result to a different result that is not null. I just don't know when that will happen, hence that is why I'm using the recursion

fetch() call not returning any data

蹲街弑〆低调 提交于 2020-12-15 07:28:50
问题 I'm having a problem with my fetch() call not working correctly. I have a recursion method that calls itself within this function, but once it passes the if statement, the data itself is not being resolved to the .then() call below. I would like to keep the recursion method within this function. Because the system that this function is calling will change the data.result to a different result that is not null. I just don't know when that will happen, hence that is why I'm using the recursion

Node.js: Fetch + pipe with excel not working

╄→гoц情女王★ 提交于 2020-12-15 01:46:58
问题 I am trying to read the contents of excel and write it into another excel. But may be i am missing something. here is relevant part of my code await fetch(fetchUrl) .then( res => new Promise((resolve, reject) => { const dest = fs.createWriteStream("./text.xlsx"); res.body.pipe(dest); res.body.on("end", () => resolve("it worked")); dest.on("error", reject); }) ) .then(x => console.log(x)); I get the following alert if i try to open the file Excel cannot open the file ’text.xlsx’ because the

Node.js: Fetch + pipe with excel not working

别等时光非礼了梦想. 提交于 2020-12-15 01:46:10
问题 I am trying to read the contents of excel and write it into another excel. But may be i am missing something. here is relevant part of my code await fetch(fetchUrl) .then( res => new Promise((resolve, reject) => { const dest = fs.createWriteStream("./text.xlsx"); res.body.pipe(dest); res.body.on("end", () => resolve("it worked")); dest.on("error", reject); }) ) .then(x => console.log(x)); I get the following alert if i try to open the file Excel cannot open the file ’text.xlsx’ because the

Node.js: Fetch + pipe with excel not working

让人想犯罪 __ 提交于 2020-12-15 01:45:40
问题 I am trying to read the contents of excel and write it into another excel. But may be i am missing something. here is relevant part of my code await fetch(fetchUrl) .then( res => new Promise((resolve, reject) => { const dest = fs.createWriteStream("./text.xlsx"); res.body.pipe(dest); res.body.on("end", () => resolve("it worked")); dest.on("error", reject); }) ) .then(x => console.log(x)); I get the following alert if i try to open the file Excel cannot open the file ’text.xlsx’ because the

Node.js: Fetch + pipe with excel not working

丶灬走出姿态 提交于 2020-12-15 01:45:13
问题 I am trying to read the contents of excel and write it into another excel. But may be i am missing something. here is relevant part of my code await fetch(fetchUrl) .then( res => new Promise((resolve, reject) => { const dest = fs.createWriteStream("./text.xlsx"); res.body.pipe(dest); res.body.on("end", () => resolve("it worked")); dest.on("error", reject); }) ) .then(x => console.log(x)); I get the following alert if i try to open the file Excel cannot open the file ’text.xlsx’ because the

What to change to prevent double request from service worker?

ぐ巨炮叔叔 提交于 2020-12-12 11:59:24
问题 Please do not mark as duplicate. This is not an exact duplicate of the other similar questions here on SO. It's more specific and fully reproducible. Clone this repo. yarn && yarn dev Go to localhost:3000 and make sure under (F12)->Applications->Service workers, the service worker is installed. Go to Network tab and refresh a few times(F5) Observe how the network requests are doubled. Example of what I see: Or if you want to do it manually follow the instructions below: yarn create-next-app