How can I speed up S3 signedUrl upload from 1Mbps

Viewed 791

I am currently utilizing s3 signedUrl's in order to hide my credentials from users on the front end. I have it set up and working but it is extremely slow around 1.2mb/s. Using speed test my wifi is showing 11.9mb/s so I don't believe it is my network. The image is only 8MB in size that I have been testing.

Server

const { uploadFile } = require("../services/aws");
app.post("/activity/image-upload", async (req, res) => {
  try {
    const { _projectId, name, type } = req.body;
    const key = `${_projectId}/activities/${name}`;
    const signedUrl = await uploadFile({ key, type });
    res.status(200).send(signedUrl);
  } catch (err) {
    console.log("/activity/upload-image err", err);
    res.status(422).send();
  }
});

AWS Service

const aws = require("aws-sdk");
const keys = require("../config/keys");

aws.config.update({
  accessKeyId: keys.aws.accessKeyId,
  secretAccessKey: keys.aws.secretAccessKey,
  useAccelerateEndpoint: true,
  signatureVersion: "v4",
  region: "my-region",
});

const s3 = new aws.S3();

exports.uploadFile = async ({ type, key }) => {
  try {
    const awsUrl = await s3.getSignedUrl("putObject", {
      Bucket: keys.aws.bucket,
      ContentType: type,
      Key: key,
      ACL: "public-read",
    });
    return awsUrl;
  } catch (err) {
    throw err;
  }
};

Front End

const handleUpload = async ({ file, onSuccess, onProgress }) => {
  try {
    const res = await api.post("/activity/image-upload", {
      type: file.type,
      name: file.name,
      _projectId,
    });
    const upload = await axios.put(res.data, file, {
      headers: {
        "Content-Type": file.type,
      },
      onUploadProgress: handleProgressChange,
    });
  } catch (err) {
    console.log("err", err);
  }
};

Image of Request Speeds enter image description here

You can see above the call to image-upload is returning in 63ms so the hang up isn't my server getting the signedURL. The axios PUT request to s3 signedURL is 6.37s. Unless I am horrible at math that for the 8MB file I am uploading that is roughly 1.2mb/s. What am I missing?

Update 7/23

Here is a picture of my speed test through Google showing upload speed of 10.8mbs. enter image description here

I tried uploading the image in s3 console to compare speeds. When I uploaded it through the s3 console it was 10.11s!!! Are their different plans that throttle speeds? I am even utilizing Transfer Acceleration and its this slow.

0 Answers
Related