Skip to content

Commit

Permalink
Merge pull request Hubs-Foundation#899 from mozilla/feature/direct-up…
Browse files Browse the repository at this point in the history
…loads

Perform upload to server directly
  • Loading branch information
gfodor authored Feb 24, 2020
2 parents 846ccdf + bb1d84e commit 0c3b960
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/api/Api.js
Original file line number Diff line number Diff line change
Expand Up @@ -927,8 +927,12 @@ export default class Project extends EventEmitter {
return project;
}

upload(blob, onUploadProgress, signal) {
return new Promise((resolve, reject) => {
async upload(blob, onUploadProgress, signal) {
// Use direct upload API, see: https://github.com/mozilla/reticulum/pull/319
const { phx_host: uploadHost } = await (await this.fetch(`https://${RETICULUM_SERVER}/api/v1/meta`)).json();
const uploadPort = new URL(`https://${RETICULUM_SERVER}`).port;

await new Promise((resolve, reject) => {
const request = new XMLHttpRequest();

const onAbort = () => {
Expand All @@ -943,7 +947,7 @@ export default class Project extends EventEmitter {
signal.addEventListener("abort", onAbort);
}

request.open("post", `https://${RETICULUM_SERVER}/api/v1/media`, true);
request.open("post", `https://${uploadHost}:${uploadPort}/api/v1/media`, true);

request.upload.addEventListener("progress", e => {
if (onUploadProgress) {
Expand Down

0 comments on commit 0c3b960

Please sign in to comment.