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.
|
||||
*/
|
||||
const API_ENDPOINT = "/api"
|
||||
const API_ENDPOINT =
|
||||
process.env.NODE_ENV === "development" ? "http://localhost:4000" : "/api"
|
||||
|
||||
const pName = R.prop("name")
|
||||
|
||||
|
@ -27,6 +28,7 @@ function MyDropzone() {
|
|||
fd.append("file", file)
|
||||
if (window) {
|
||||
const streamSaver = require("streamsaver")
|
||||
console.log("streamSaver", streamSaver)
|
||||
const url = API_ENDPOINT + "/siafile"
|
||||
fetch(url, {
|
||||
method: "POST",
|
||||
|
@ -67,7 +69,8 @@ function MyDropzone() {
|
|||
pump()
|
||||
})
|
||||
.catch(e => {
|
||||
setError(e)
|
||||
// setError(e)
|
||||
console.log("error is", e)
|
||||
setLoading(false)
|
||||
})
|
||||
}
|
||||
|
|
|
@ -68,7 +68,6 @@ export class Server {
|
|||
const selectFile = R.path(["files", "file"])
|
||||
try {
|
||||
const file: any = selectFile(req)
|
||||
console.log("file is", req.files)
|
||||
|
||||
const { data: stream } = await siad.post("/renter/stream", file.data, {
|
||||
headers: {
|
||||
|
@ -80,14 +79,7 @@ export class Server {
|
|||
res.attachment(file.name)
|
||||
res.set("Content-Type", "application/octet-stream")
|
||||
|
||||
stream.on("data", chunk => {
|
||||
console.log("chunk...")
|
||||
res.write(chunk)
|
||||
})
|
||||
stream.on("end", () => {
|
||||
console.log("end...")
|
||||
res.end()
|
||||
})
|
||||
stream.pipe(res)
|
||||
} catch (e) {
|
||||
console.log("e is", e)
|
||||
return res.json({ error: e.message })
|
||||
|
|
Reference in New Issue