koa-router
ile Koa'da bir POST istek işleyicisinden bir karşıdan yüklemeyi tetiklemeye çalışıyorum. Esasen, böyle bir şey yapmaya çalışıyorum:Koa'da bir POST isteği dosya indir
app.js
const Koa = require('koa')
const router = require('./router')
const app = new Koa()
app.use(router.routes())
app.use(router.allowedMethods())
app.listen(3000)
router.js
const fs = require('fs')
const Router = require('koa-router')
const router = new Router()
router.post('/generate', function *() {
const path = `${__dirname}/test.txt`
this.body = fs.createReadStream(path)
this.set('Content-disposition', 'attachment; filename= test.txt')
})
module.exports = router
client.js
const { fetch } = window;
const request = {
method: 'POST',
body: JSON.stringify({ fake: 'data' })
}
// Make the POST request
fetch('/generate', request)
Ancak, POST isteği gönderildiğinde hiçbir şey olmuyor. Sunucu konsolunda veya tarayıcı konsolunda da herhangi bir hata alamıyorum. Herhangi bir yardım takdir edilecektir!
Ben senin sorunun sunucu tarafı kod ama istemci tarafında olmadığını düşünüyorum. Alınan verilerle ne yaptığınızı gösterir misiniz? getirme form teslim olarak çalışmayacak, yanıtı işlemek zorunda ve eğer Vedran onun müşteri tarafında kod ne yaptığını indirmek istiyorsanız. –