Amplify-js: How can I upload relatively large file to S3 with slower connection?

Created on 15 Nov 2018  路  5Comments  路  Source: aws-amplify/amplify-js

What AWS Services are you utilizing?

S3

Provide additional details e.g. code snippets

Currently uploading a file via Storage.put (I am using Storage.vault to be specific) method fails with slower connection.

If I choose Network -> Online -> Slow 3g option and upload any file, it is split into 4 parts and each part fails if it does not get uploaded within 2 minutes.

screenshot from 2018-11-14 16-53-05

As you can see requests are 'cancelled' which suggests they are cancelled by the client, not the server?

This results in users being unable to upload 17mb file using any public wifi (cafe etc.)

How can I extend (or even turn off) this timeout. I don't care how long upload will take (our users are prepared that it might take a while. I just care that it doesn't fail.

Storage question

Most helpful comment

Hi @mpodlasin ,

Amplify Storage currently doesn't have any in-built options to update the http options for timeout and retires. However, we do expose AWS object from the amplify library.
I think for your use case you would need to set the httpOptions for S3 (https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html#constructor-property) . For this, you could import AWS from aws-amplify and then use AWS.config.s3 (https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/Config.html#s3-property) to set the httpOptions before calling put or get from the Storage library.

import {AWS} from aws-amplify;

AWS.config.s3 = { httpOptions: { /* ... */ } };

All 5 comments

Hi @mpodlasin ,

Amplify Storage currently doesn't have any in-built options to update the http options for timeout and retires. However, we do expose AWS object from the amplify library.
I think for your use case you would need to set the httpOptions for S3 (https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html#constructor-property) . For this, you could import AWS from aws-amplify and then use AWS.config.s3 (https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/Config.html#s3-property) to set the httpOptions before calling put or get from the Storage library.

import {AWS} from aws-amplify;

AWS.config.s3 = { httpOptions: { /* ... */ } };

@nidsharm Thank you for answering.

Actually in my version of amplify the AWS object is undefined. I looked at the source and I don't see it exported.

@mpodlasin I imported AWS from Amplify doing this.

import { AWS } from "@aws-amplify/core/lib/Facet";

I think it works! Thanks guys!

Closing this issue, please feel free to re-open if there is an issue.

Was this page helpful?
0 / 5 - 0 ratings