Upload Images to S3 using Amplify, Flutter

AWS Amplify has support for Flutter application to interact with its cloud service. We can take advantage of inbuilt Cognito Pool authentication to provide seamless file management and user created contents.

Using Amplify we could accomplish the task with less boiler code.

Following is an example snippet:

uploadImage = async uri => {
  const response = await fetch(localImgUri)
  const blob = await response.blob() // format image data into blob
  const folder = 'images'
  const fileName = localImgUri // Get file name from Uri
  await Storage.put(folder + '/' + fileName, blob, {
   contentType: 'image/jpeg',
   level: 'public'
  }).then(data => console.log(data))
    .catch(err => console.log(err))
 }