Giter VIP home page Giter VIP logo

amplify-s3-chunk-upload's Introduction

AWS Amplify S3 upload

A custom storage upload plugin for AWS Amplify. Instead of reading file completely in memory, it helps to read file chunk by chunk.

Currently while using Amplify library to upload a to AWS S3 we have to read that file into memory and which could cause OutOfMemory issues while uploading large files in ReactNative. There is no support to read the file in small chunks.

The Amplify Storage plugin supports Managed upload. It will divide the file into small chunks and upload them in batches.

The Amplify library supports custom plugins, using which we can connect with services other than AWS or add a wrapper to AWS services.

To support the uploading of large files using Amplify, I have used the same mechanism as a custom plugin.

NPM Library amplify-s3-chunk-upload

AWS Sdk Support


Usage

Install

npm i -s amplify-s3-chunk-upload

Configure Storage plugin in App.js (ReactNative)

import { StorageChunkUpload } from 'amplify-s3-chunk-upload';
import { Credentials } from '@aws-amplify/core';



// put following code after Amplify.configure

// Load StorageChunkUpload Plugin
const storagePlugin = new StorageChunkUpload({}, Credentials);
Storage.addPluggable(storagePlugin);
storagePlugin.configure(config);

File upload call

// get File stats
const { size } = await RNFS.stat(fileURI);

// here we are simulating an array of bytes
const fileObject = {
  // set the size
  size: size,

  // here we will read file as per bodyStart & bodyEnd, this will avoid reading complete file in the memory.
  slice: (bodyStart, bodyEnd) => {
    // Here in this sample code, we are using react-native-fs to read files.
    return RNFS.read(fileURI, bodyEnd - bodyStart, bodyStart, 'base64')
      .then((data) => Buffer.from(data, 'base64'))
      .catch((error) => {
        // Log error if required.
      });
    },
  };

  // Upload call, for parameters, refer to Amplify docs.
  const result = await Storage.put(`Your-file-name.mp4`, fileObject, {
    contentType: 'video/mp4',
    level: 'protected',
    provider: 'StorageChunkUpload',
  });

Since we are making standard Storage.put call and the underlying code also uses the same Amplify Library code, you can pass all other parameters such as progressCallback etc.

amplify-s3-chunk-upload's People

Contributors

walvekarnikhil avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

amplify-s3-chunk-upload's Issues

Feat: Add custom S3 provider to read file chunk by chunk

Currently, with Amplify we have to read the full file in the blob and then pass it to the Storage.put.

uploadToStorage = async pathToImageFile => {
  try {
    const response = await fetch(pathToImageFile)

    const blob = await response.blob()

    Storage.put('yourKeyHere.jpeg', blob, {
      contentType: 'image/jpeg',
    })
  } catch (err) {
    console.log(err)
  }
}

This could lead to memory issues while uploading large files on Android.

The Amplify supports managed multi-part upload for large files. The files are sent in a batch of 4, each could max of 5mb. But currently, the file has to be read in the blob.

Expected:
There should be a way to read the file in chunks, so we don't end up reading the full file in the blob.

Getting axios-http-handler Error: Request failed with status code 403

Hi there. Found your plugin and trying to use it in my project to upload large files.
It works ok with files less than 5Mb (BTW: nothing said about that we need to read the file and pass a body inside)
But when we get to larger files, I am getting 403 error from S3.
Tried to debug your lib, the issue happens when it calls this.createMultiPartUpload.

Request

{
  "url": "https://*****.s3.us-west-2.amazonaws.com/protected/IMG_0044.MOV?uploads=",
  "method": "POST",
  "headers": {
    "content-type": "video/mp4",
    "x-amz-user-agent": "aws-sdk-js/3.6.1 os/macOS/11.2.2 lang/js md/browser/Chrome_88.0.4324.192 api/s3/3.6.1 aws-amplify/3.8.16_react-native",
    "user-agent": "aws-sdk-js/3.6.1 aws-amplify/3.8.16_react-native",
    "amz-sdk-invocation-id": "27fd6022-121a-4391-b1ad-d7490b742b7d",
    "amz-sdk-request": "attempt=1; max=3",
    "x-amz-date": "20210312T134559Z",
    "x-amz-security-token": "IQoJb3JpZ2luX2VjEH0aCXVzLXdlc3QtMiJHMEUCIQCYOSBKsDEInBVvKHeY1LBIe6glOANu4xsDKhNqKyVzNwIgYMpuoa3AmPrmkVeX6tuERXzodRLi+sr9uJx5JCd9ZhUqzQQIpv//////////ARAAGgw1ODQ5MTY0NTk5MTIiDAmI8KD8Nz5N4j90wyqhBLQzKDoqoKgyHj6/hLyEn7LFqrp4Hf6azC/ZOjLYZQjEK+TxQel9kEErlIQt1tRnZKCpY/dARDe3hCD51Vky7OJv8Z9d5o7gMQEpMrt5SmdZg52gNDf5GoU6JKEGYywhFt9O8uSOHu09+5QUtdiUJc3tWHRCMg5TyzB50kRC8b6kF+rggmwD0EaMauI19RwcEMeJgy7u9gqcNyfWRU/ns/DBlJ5d1U6cctK4WW3wd3mBElsE6WLQ+E92L9apksio9CCFsgOimSXDvOIGXay0qipijNpFxkXUtT3GHVpehrLJy95HVWsFyFxy4aeEmNYzdf7X2bc1L+ICw4ISexibtOroUacqy1ynIMSNpraioWkn/NK+OocaDzdwhPONJLOmNO4VOM0bOc7attiTjEQwVhrIEjZIatkjSP61rLLUYmK8s5hw43lIohS3k05MQGItZ3TbT9T8i9iE5SgQ2zZnVeOPlkKYgwR87MAtfWsb0kUYeYraxrksSbieaC+wLo81ZATstHG/naQv1Xxzv2PdzgM3g7G1cO3gjqCX8W+YVH8tDA+/TIUm3qvty8LPxbLgNwhfc9QcVps3NAWrvetR8YvsoDNjPmlmysOnRC1N1k4dztwhnYNEsn7MuY2ztvvgzuRANvCyei6EvNN/gQP1eMYZmvCXy4Xzq2n2Etg7y7XWcYw5qJjy+lMBzuCEOOOqoHrRC7qkKs4k5y4WmZpzstgnMK7QrYIGOoUCsHWdF5HQ57y0H/dMOHq0v00Nh1ZYQJe06bcSiz5+AFpYVk0wDya4w0izVYf40KyUBR3nzN6M2uHXeficQ2agX/+CLc23NOEaIjIEstzxH6Kk7Y/05slE3wT19RX6ICLmEyA/ulLbbFI7fX7KEiKTbmVuXgQ9O3h2aICvjgdlsEBOtW882NfPFdELqsR1jaY0QQAu1RlFxB67Pr5IgNXzYRkT9PIZ15P8LF8RNRKIgfXl/teedwnlHzm9VRV2sND8+GU0uKaueE137TGcgnty3O3+suSbnJWD+ZJ8aOHTdn2gDUaCAHiIzQuF1bFAgSVQr1mz/UOzq9SicfQPnvucYJKQFGH/",
    "x-amz-content-sha256": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
    "authorization": "AWS4-HMAC-SHA256 Credential=ASIAYQL544GEDHU4GE5W/20210312/us-west-2/s3/aws4_request, SignedHeaders=amz-sdk-invocation-id;amz-sdk-request;content-type;host;x-amz-content-sha256;x-amz-date;x-amz-security-token;x-amz-user-agent, Signature=58c54fb3973e44798d0261b26f2a2ca0fdc27d7c5ed5d91123e9d90733871c92"
  }
}

Response

<?xml version="1.0" encoding="UTF-8"?>
<Error>
	<Code>SignatureDoesNotMatch</Code>
	<Message>The request signature we calculated does not match the signature you provided. Check your key and signing method.</Message>
	<AWSAccessKeyId>*****************</AWSAccessKeyId>
	<StringToSign>AWS4-HMAC-SHA256
20210312T134559Z
20210312/us-west-2/s3/aws4_request
d97d9fdb1438c72d14d8b04da2086150fc3ba3dcbe5e3ec5389bbd0d4c01dc79</StringToSign>
	<SignatureProvided>58c54fb3973e44798d0261b26f2a2ca0fdc27d7c5ed5d91123e9d90733871c92</SignatureProvided>
	<StringToSignBytes>41 57 53 34 2d 48 4d 41 43 2d 53 48 41 32 35 36 0a 32 30 32 31 30 33 31 32 54 31 33 34 35 35 39 5a 0a 32 30 32 31 30 33 31 32 2f 75 73 2d 77 65 73 74 2d 32 2f 73 33 2f 61 77 73 34 5f 72 65 71 75 65 73 74 0a 64 39 37 64 39 66 64 62 31 34 33 38 63 37 32 64 31 34 64 38 62 30 34 64 61 32 30 38 36 31 35 30 66 63 33 62 61 33 64 63 62 65 35 65 33 65 63 35 33 38 39 62 62 64 30 64 34 63 30 31 64 63 37 39</StringToSignBytes>
	<CanonicalRequest>POST
/protected/IMG_0044.MOV
uploads=
amz-sdk-invocation-id:27fd6022-121a-4391-b1ad-d7490b742b7d
amz-sdk-request:attempt=1; max=3
content-type:
host:*****.s3.us-west-2.amazonaws.com
x-amz-content-sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
x-amz-date:20210312T134559Z
x-amz-security-token:IQoJb3JpZ2luX2VjEH0aCXVzLXdlc3QtMiJHMEUCIQCYOSBKsDEInBVvKHeY1LBIe6glOANu4xsDKhNqKyVzNwIgYMpuoa3AmPrmkVeX6tuERXzodRLi+sr9uJx5JCd9ZhUqzQQIpv//////////ARAAGgw1ODQ5MTY0NTk5MTIiDAmI8KD8Nz5N4j90wyqhBLQzKDoqoKgyHj6/hLyEn7LFqrp4Hf6azC/ZOjLYZQjEK+TxQel9kEErlIQt1tRnZKCpY/dARDe3hCD51Vky7OJv8Z9d5o7gMQEpMrt5SmdZg52gNDf5GoU6JKEGYywhFt9O8uSOHu09+5QUtdiUJc3tWHRCMg5TyzB50kRC8b6kF+rggmwD0EaMauI19RwcEMeJgy7u9gqcNyfWRU/ns/DBlJ5d1U6cctK4WW3wd3mBElsE6WLQ+E92L9apksio9CCFsgOimSXDvOIGXay0qipijNpFxkXUtT3GHVpehrLJy95HVWsFyFxy4aeEmNYzdf7X2bc1L+ICw4ISexibtOroUacqy1ynIMSNpraioWkn/NK+OocaDzdwhPONJLOmNO4VOM0bOc7attiTjEQwVhrIEjZIatkjSP61rLLUYmK8s5hw43lIohS3k05MQGItZ3TbT9T8i9iE5SgQ2zZnVeOPlkKYgwR87MAtfWsb0kUYeYraxrksSbieaC+wLo81ZATstHG/naQv1Xxzv2PdzgM3g7G1cO3gjqCX8W+YVH8tDA+/TIUm3qvty8LPxbLgNwhfc9QcVps3NAWrvetR8YvsoDNjPmlmysOnRC1N1k4dztwhnYNEsn7MuY2ztvvgzuRANvCyei6EvNN/gQP1eMYZmvCXy4Xzq2n2Etg7y7XWcYw5qJjy+lMBzuCEOOOqoHrRC7qkKs4k5y4WmZpzstgnMK7QrYIGOoUCsHWdF5HQ57y0H/dMOHq0v00Nh1ZYQJe06bcSiz5+AFpYVk0wDya4w0izVYf40KyUBR3nzN6M2uHXeficQ2agX/+CLc23NOEaIjIEstzxH6Kk7Y/05slE3wT19RX6ICLmEyA/ulLbbFI7fX7KEiKTbmVuXgQ9O3h2aICvjgdlsEBOtW882NfPFdELqsR1jaY0QQAu1RlFxB67Pr5IgNXzYRkT9PIZ15P8LF8RNRKIgfXl/teedwnlHzm9VRV2sND8+GU0uKaueE137TGcgnty3O3+suSbnJWD+ZJ8aOHTdn2gDUaCAHiIzQuF1bFAgSVQr1mz/UOzq9SicfQPnvucYJKQFGH/
x-amz-user-agent:aws-sdk-js/3.6.1 os/macOS/11.2.2 lang/js md/browser/Chrome_88.0.4324.192 api/s3/3.6.1 aws-amplify/3.8.16_react-native

amz-sdk-invocation-id;amz-sdk-request;content-type;host;x-amz-content-sha256;x-amz-date;x-amz-security-token;x-amz-user-agent
e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855</CanonicalRequest>
	<CanonicalRequestBytes>50 4f 53 54 0a 2f 70 75 62 6c 69 63 2f 49 4d 47 5f 30 30 34 34 2e 4d 4f 56 0a 75 70 6c 6f 61 64 73 3d 0a 61 6d 7a 2d 73 64 6b 2d 69 6e 76 6f 63 61 74 69 6f 6e 2d 69 64 3a 32 37 66 64 36 30 32 32 2d 31 32 31 61 2d 34 33 39 31 2d 62 31 61 64 2d 64 37 34 39 30 62 37 34 32 62 37 64 0a 61 6d 7a 2d 73 64 6b 2d 72 65 71 75 65 73 74 3a 61 74 74 65 6d 70 74 3d 31 3b 20 6d 61 78 3d 33 0a 63 6f 6e 74 65 6e 74 2d 74 79 70 65 3a 0a 68 6f 73 74 3a 6f 6e 71 6d 6f 62 69 6c 65 61 70 70 2d 75 70 6c 6f 61 64 73 31 30 31 36 31 36 2d 64 65 76 2e 73 33 2e 75 73 2d 77 65 73 74 2d 32 2e 61 6d 61 7a 6f 6e 61 77 73 2e 63 6f 6d 0a 78 2d 61 6d 7a 2d 63 6f 6e 74 65 6e 74 2d 73 68 61 32 35 36 3a 65 33 62 30 63 34 34 32 39 38 66 63 31 63 31 34 39 61 66 62 66 34 63 38 39 39 36 66 62 39 32 34 32 37 61 65 34 31 65 34 36 34 39 62 39 33 34 63 61 34 39 35 39 39 31 62 37 38 35 32 62 38 35 35 0a 78 2d 61 6d 7a 2d 64 61 74 65 3a 32 30 32 31 30 33 31 32 54 31 33 34 35 35 39 5a 0a 78 2d 61 6d 7a 2d 73 65 63 75 72 69 74 79 2d 74 6f 6b 65 6e 3a 49 51 6f 4a 62 33 4a 70 5a 32 6c 75 58 32 56 6a 45 48 30 61 43 58 56 7a 4c 58 64 6c 63 33 51 74 4d 69 4a 48 4d 45 55 43 49 51 43 59 4f 53 42 4b 73 44 45 49 6e 42 56 76 4b 48 65 59 31 4c 42 49 65 36 67 6c 4f 41 4e 75 34 78 73 44 4b 68 4e 71 4b 79 56 7a 4e 77 49 67 59 4d 70 75 6f 61 33 41 6d 50 72 6d 6b 56 65 58 36 74 75 45 52 58 7a 6f 64 52 4c 69 2b 73 72 39 75 4a 78 35 4a 43 64 39 5a 68 55 71 7a 51 51 49 70 76 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 41 52 41 41 47 67 77 31 4f 44 51 35 4d 54 59 30 4e 54 6b 35 4d 54 49 69 44 41 6d 49 38 4b 44 38 4e 7a 35 4e 34 6a 39 30 77 79 71 68 42 4c 51 7a 4b 44 6f 71 6f 4b 67 79 48 6a 36 2f 68 4c 79 45 6e 37 4c 46 71 72 70 34 48 66 36 61 7a 43 2f 5a 4f 6a 4c 59 5a 51 6a 45 4b 2b 54 78 51 65 6c 39 6b 45 45 72 6c 49 51 74 31 74 52 6e 5a 4b 43 70 59 2f 64 41 52 44 65 33 68 43 44 35 31 56 6b 79 37 4f 4a 76 38 5a 39 64 35 6f 37 67 4d 51 45 70 4d 72 74 35 53 6d 64 5a 67 35 32 67 4e 44 66 35 47 6f 55 36 4a 4b 45 47 59 79 77 68 46 74 39 4f 38 75 53 4f 48 75 30 39 2b 35 51 55 74 64 69 55 4a 63 33 74 57 48 52 43 4d 67 35 54 79 7a 42 35 30 6b 52 43 38 62 36 6b 46 2b 72 67 67 6d 77 44 30 45 61 4d 61 75 49 31 39 52 77 63 45 4d 65 4a 67 79 37 75 39 67 71 63 4e 79 66 57 52 55 2f 6e 73 2f 44 42 6c 4a 35 64 31 55 36 63 63 74 4b 34 57 57 33 77 64 33 6d 42 45 6c 73 45 36 57 4c 51 2b 45 39 32 4c 39 61 70 6b 73 69 6f 39 43 43 46 73 67 4f 69 6d 53 58 44 76 4f 49 47 58 61 79 30 71 69 70 69 6a 4e 70 46 78 6b 58 55 74 54 33 47 48 56 70 65 68 72 4c 4a 79 39 35 48 56 57 73 46 79 46 78 79 34 61 65 45 6d 4e 59 7a 64 66 37 58 32 62 63 31 4c 2b 49 43 77 34 49 53 65 78 69 62 74 4f 72 6f 55 61 63 71 79 31 79 6e 49 4d 53 4e 70 72 61 69 6f 57 6b 6e 2f 4e 4b 2b 4f 6f 63 61 44 7a 64 77 68 50 4f 4e 4a 4c 4f 6d 4e 4f 34 56 4f 4d 30 62 4f 63 37 61 74 74 69 54 6a 45 51 77 56 68 72 49 45 6a 5a 49 61 74 6b 6a 53 50 36 31 72 4c 4c 55 59 6d 4b 38 73 35 68 77 34 33 6c 49 6f 68 53 33 6b 30 35 4d 51 47 49 74 5a 33 54 62 54 39 54 38 69 39 69 45 35 53 67 51 32 7a 5a 6e 56 65 4f 50 6c 6b 4b 59 67 77 52 38 37 4d 41 74 66 57 73 62 30 6b 55 59 65 59 72 61 78 72 6b 73 53 62 69 65 61 43 2b 77 4c 6f 38 31 5a 41 54 73 74 48 47 2f 6e 61 51 76 31 58 78 7a 76 32 50 64 7a 67 4d 33 67 37 47 31 63 4f 33 67 6a 71 43 58 38 57 2b 59 56 48 38 74 44 41 2b 2f 54 49 55 6d 33 71 76 74 79 38 4c 50 78 62 4c 67 4e 77 68 66 63 39 51 63 56 70 73 33 4e 41 57 72 76 65 74 52 38 59 76 73 6f 44 4e 6a 50 6d 6c 6d 79 73 4f 6e 52 43 31 4e 31 6b 34 64 7a 74 77 68 6e 59 4e 45 73 6e 37 4d 75 59 32 7a 74 76 76 67 7a 75 52 41 4e 76 43 79 65 69 36 45 76 4e 4e 2f 67 51 50 31 65 4d 59 5a 6d 76 43 58 79 34 58 7a 71 32 6e 32 45 74 67 37 79 37 58 57 63 59 77 35 71 4a 6a 79 2b 6c 4d 42 7a 75 43 45 4f 4f 4f 71 6f 48 72 52 43 37 71 6b 4b 73 34 6b 35 79 34 57 6d 5a 70 7a 73 74 67 6e 4d 4b 37 51 72 59 49 47 4f 6f 55 43 73 48 57 64 46 35 48 51 35 37 79 30 48 2f 64 4d 4f 48 71 30 76 30 30 4e 68 31 5a 59 51 4a 65 30 36 62 63 53 69 7a 35 2b 41 46 70 59 56 6b 30 77 44 79 61 34 77 30 69 7a 56 59 66 34 30 4b 79 55 42 52 33 6e 7a 4e 36 4d 32 75 48 58 65 66 69 63 51 32 61 67 58 2f 2b 43 4c 63 32 33 4e 4f 45 61 49 6a 49 45 73 74 7a 78 48 36 4b 6b 37 59 2f 30 35 73 6c 45 33 77 54 31 39 52 58 36 49 43 4c 6d 45 79 41 2f 75 6c 4c 62 62 46 49 37 66 58 37 4b 45 69 4b 54 62 6d 56 75 58 67 51 39 4f 33 68 32 61 49 43 76 6a 67 64 6c 73 45 42 4f 74 57 38 38 32 4e 66 50 46 64 45 4c 71 73 52 31 6a 61 59 30 51 51 41 75 31 52 6c 46 78 42 36 37 50 72 35 49 67 4e 58 7a 59 52 6b 54 39 50 49 5a 31 35 50 38 4c 46 38 52 4e 52 4b 49 67 66 58 6c 2f 74 65 65 64 77 6e 6c 48 7a 6d 39 56 52 56 32 73 4e 44 38 2b 47 55 30 75 4b 61 75 65 45 31 33 37 54 47 63 67 6e 74 79 33 4f 33 2b 73 75 53 62 6e 4a 57 44 2b 5a 4a 38 61 4f 48 54 64 6e 32 67 44 55 61 43 41 48 69 49 7a 51 75 46 31 62 46 41 67 53 56 51 72 31 6d 7a 2f 55 4f 7a 71 39 53 69 63 66 51 50 6e 76 75 63 59 4a 4b 51 46 47 48 2f 0a 78 2d 61 6d 7a 2d 75 73 65 72 2d 61 67 65 6e 74 3a 61 77 73 2d 73 64 6b 2d 6a 73 2f 33 2e 36 2e 31 20 6f 73 2f 6d 61 63 4f 53 2f 31 31 2e 32 2e 32 20 6c 61 6e 67 2f 6a 73 20 6d 64 2f 62 72 6f 77 73 65 72 2f 43 68 72 6f 6d 65 5f 38 38 2e 30 2e 34 33 32 34 2e 31 39 32 20 61 70 69 2f 73 33 2f 33 2e 36 2e 31 20 61 77 73 2d 61 6d 70 6c 69 66 79 2f 33 2e 38 2e 31 36 5f 72 65 61 63 74 2d 6e 61 74 69 76 65 0a 0a 61 6d 7a 2d 73 64 6b 2d 69 6e 76 6f 63 61 74 69 6f 6e 2d 69 64 3b 61 6d 7a 2d 73 64 6b 2d 72 65 71 75 65 73 74 3b 63 6f 6e 74 65 6e 74 2d 74 79 70 65 3b 68 6f 73 74 3b 78 2d 61 6d 7a 2d 63 6f 6e 74 65 6e 74 2d 73 68 61 32 35 36 3b 78 2d 61 6d 7a 2d 64 61 74 65 3b 78 2d 61 6d 7a 2d 73 65 63 75 72 69 74 79 2d 74 6f 6b 65 6e 3b 78 2d 61 6d 7a 2d 75 73 65 72 2d 61 67 65 6e 74 0a 65 33 62 30 63 34 34 32 39 38 66 63 31 63 31 34 39 61 66 62 66 34 63 38 39 39 36 66 62 39 32 34 32 37 61 65 34 31 65 34 36 34 39 62 39 33 34 63 61 34 39 35 39 39 31 62 37 38 35 32 62 38 35 35</CanonicalRequestBytes>
	<RequestId>ZCTSQG36Z15663CE</RequestId>
	<HostId>w8NPlNdeE8ALPjYVoeJKiXrEk2AuyAfLnuYvxKpBsXzJmC1AuH5d4XEQ7zIRjZebhhjfUr6Nhtk=</HostId>
</Error>

Code

import awsconfig from './src/aws-exports';
Amplify.configure(awsconfig);

// load StorageChunkUpload Plugin
const storagePlugin = new StorageChunkUpload({}, Credentials);
Storage.addPluggable(storagePlugin);
storagePlugin.configure(config);
const fileObject = {
  // set the size
  size: file.size,
  // here we will read file as per bodyStart & bodyEnd, this will avoid reading complete file in the memory.
  slice: (bodyStart, bodyEnd) => {
    console.log('base.slice()', bodyStart, bodyEnd);
    return RNFS.read(
      file.path,
      bodyEnd - bodyStart,
      bodyStart,
      'base64',
    )
      .then((data) => Buffer.from(data, 'base64'))
      .catch((err) => console.error(err));
  },
};

// upload call, for parameters, refer to Amplify docs.
const result = await Storage.put(file.filename, fileObject, {
  contentType: file.mime,
  level: 'protected',
  provider: 'StorageChunkUpload',
  progressCallback: (progress) => {
    console.log('base.progress()', progress);
  },
});

console.log('UPLOAD RESULT STANDARD', result);

Any ideas?

P.S. It is a React Native project

completeCallback never gets called?

Thanks for your work!
What I wanna do is upload a 500MB large video file to S3.
I tried to use fetch to read blob and pass it to Storage.put(), which didn't work for some reasons.
So I added this plugin like README says and it kinda works... I can upload a file.
But it seems like completeCallback never gets called(progressCallback does, also taking so much time to upload...)
And I'm wondering if that is how it's supposed to be?

Files < minPartSize not uploaded correctly

If the total file size is < minPartSize (as defined in StorageChunkManagedUpload) then the following JSON object encoded in base64 is uploaded to S3 instead of the file contents:

{"size":<file-size-in-bytes>}

It appears that the library uploads the fileObject itself instead of calling slice().

As a workaround if the file size is < minPartSize we need to read the file in full and pass that as the fileObject to Storage.put().

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.