UI for Zipcoin Blue

aws.js 1.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. const tslib_1 = require("tslib");
  4. const http_1 = require("../http");
  5. function s3SignedUpload(config, presignedPostParams, zip, { progress }) {
  6. return tslib_1.__awaiter(this, void 0, void 0, function* () {
  7. const { req } = yield http_1.createRequest(config, 'post', presignedPostParams.url);
  8. return new Promise((resolve, reject) => {
  9. zip.on('error', (err) => {
  10. reject(err);
  11. });
  12. let bufs = [];
  13. zip.on('data', (buf) => {
  14. bufs.push(buf);
  15. });
  16. zip.on('end', () => {
  17. req
  18. .buffer()
  19. .field(presignedPostParams.fields)
  20. .field('file', Buffer.concat(bufs))
  21. .on('progress', (event) => {
  22. if (progress) {
  23. progress(event.loaded, event.total);
  24. }
  25. })
  26. .end((err, res) => {
  27. if (err) {
  28. return reject(err);
  29. }
  30. if (res.status !== 204) {
  31. // TODO: log body for debug purposes?
  32. return reject(new Error(`Unexpected status code from AWS: ${res.status}`));
  33. }
  34. resolve();
  35. });
  36. });
  37. });
  38. });
  39. }
  40. exports.s3SignedUpload = s3SignedUpload;