add polyfill and pipe better

This commit is contained in:
Eddie Wang 2019-12-05 12:22:28 -05:00
parent 71a7749721
commit 1e7ceb3979
No known key found for this signature in database
GPG Key ID: DBFB3E83121BEDD1
2 changed files with 6 additions and 11 deletions

View File

@ -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)
})
}

View File

@ -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 })