add polyfill and pipe better
This commit is contained in:
parent
71a7749721
commit
1e7ceb3979
|
@ -8,7 +8,8 @@ import { CircularProgress } from "@material-ui/core"
|
||||||
/**
|
/**
|
||||||
* nginx is setup to automatically handle and rewrite the url path.
|
* nginx is setup to automatically handle and rewrite the url path.
|
||||||
*/
|
*/
|
||||||
const API_ENDPOINT = "/api"
|
const API_ENDPOINT =
|
||||||
|
process.env.NODE_ENV === "development" ? "http://localhost:4000" : "/api"
|
||||||
|
|
||||||
const pName = R.prop("name")
|
const pName = R.prop("name")
|
||||||
|
|
||||||
|
@ -27,6 +28,7 @@ function MyDropzone() {
|
||||||
fd.append("file", file)
|
fd.append("file", file)
|
||||||
if (window) {
|
if (window) {
|
||||||
const streamSaver = require("streamsaver")
|
const streamSaver = require("streamsaver")
|
||||||
|
console.log("streamSaver", streamSaver)
|
||||||
const url = API_ENDPOINT + "/siafile"
|
const url = API_ENDPOINT + "/siafile"
|
||||||
fetch(url, {
|
fetch(url, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
|
@ -67,7 +69,8 @@ function MyDropzone() {
|
||||||
pump()
|
pump()
|
||||||
})
|
})
|
||||||
.catch(e => {
|
.catch(e => {
|
||||||
setError(e)
|
// setError(e)
|
||||||
|
console.log("error is", e)
|
||||||
setLoading(false)
|
setLoading(false)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -68,7 +68,6 @@ export class Server {
|
||||||
const selectFile = R.path(["files", "file"])
|
const selectFile = R.path(["files", "file"])
|
||||||
try {
|
try {
|
||||||
const file: any = selectFile(req)
|
const file: any = selectFile(req)
|
||||||
console.log("file is", req.files)
|
|
||||||
|
|
||||||
const { data: stream } = await siad.post("/renter/stream", file.data, {
|
const { data: stream } = await siad.post("/renter/stream", file.data, {
|
||||||
headers: {
|
headers: {
|
||||||
|
@ -80,14 +79,7 @@ export class Server {
|
||||||
res.attachment(file.name)
|
res.attachment(file.name)
|
||||||
res.set("Content-Type", "application/octet-stream")
|
res.set("Content-Type", "application/octet-stream")
|
||||||
|
|
||||||
stream.on("data", chunk => {
|
stream.pipe(res)
|
||||||
console.log("chunk...")
|
|
||||||
res.write(chunk)
|
|
||||||
})
|
|
||||||
stream.on("end", () => {
|
|
||||||
console.log("end...")
|
|
||||||
res.end()
|
|
||||||
})
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log("e is", e)
|
console.log("e is", e)
|
||||||
return res.json({ error: e.message })
|
return res.json({ error: e.message })
|
||||||
|
|
Reference in New Issue