question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can't upload images from my javascript app to Storage setup via the CLI

See original GitHub issue

I’ve added Storage via the CLI and given permission to Authenticated (read, write, delete) and Guest users (read only) and then pushed.

I’ve got an app that I have to log into (which is working) and then I’ve then got a form that tries to upload an image to the storage but its failing with 403 forbidden. I’m not sure where to go from here to get it to authenticate or to try to work out what the issue might be.

Any ideas?

To Reproduce

Steps to reproduce the behavior: run amplify add Storage or amplify update storage if already added

image

Then using this little helper:

import { Storage } from "aws-amplify";

export async function s3Upload(sourceFile, targetFilename) {
  const filename = targetFilename ?? `${Date.now()}-${sourceFile.name}`;

  const stored = await Storage.put(filename, sourceFile, {
    contentType: sourceFile.type,
  });

  console.info("S3 Response", stored);

  return stored.key;
}

Used in my onChange handler for my file input:

const handleFileChange = async (event) => {
  console.info("File changed", event.target.files[0]);
  const file = event.target.files[0];
  const attachment = await s3Upload(file);
  console.info("File uploaded to " + attachment );
}

When using the form I get this error in the console:

image

Expected behavior

Adding Storage and allowing the permissions I have for Authenticated users I would expect that I could push images up once logged in (Authenticated right?).

Desktop (please complete the following information):

  • OS: Win 10
  • Browser chrome
  • Version 87.0.4280.88

Additional context Not sure if this is related: https://github.com/aws-amplify/amplify-console/issues/1403

This issue was copied from https://github.com/aws-amplify/amplify-console/issues/1427 as I raised it in the wrong repo.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:22 (10 by maintainers)

github_iconTop GitHub Comments

2reactions
amhinsoncommented, Jan 13, 2021

Hmm I’m still having no luck reproducing this with a federated Google user uploading a file to S3. This does appear to be similar to other issues such as: https://github.com/aws-amplify/amplify-cli/issues/4055 https://github.com/aws-amplify/amplify-js/issues/5729 https://github.com/aws-amplify/amplify-js/issues/1094

I know there are a lot of potential solutions presented in those, but have you looked deeper into the roles/policies/groups as suggested in the other issues?

Another suggestion would be to create a sample app from scratch and document every single step to see if you experience the same behavior, since it looks like the original reproduction steps just start with update storage instead of add storage. If the same thing happens, then providing those complete reproduction steps here would be great for us to debug on our side. If you can’t reproduce it with the new app, then you can compare what might be different in the policies & S3 bucket.

Let me know what you find! 👍

1reaction
edwardfoylecommented, Jan 8, 2021

@PeteDuncanson if you’re able to make other authenticated calls successfully then it seems like you have authenticated properly. Maybe read through the docs here: https://docs.amplify.aws/lib/auth/social/q/platform/js to make sure. Hopefully someone on the JS team can help you debug further

Read more comments on GitHub >

github_iconTop Results From Across the Web

How To Upload a File to Object Storage with Node.js
Create a Node.js app to upload a file to your DigitalOcean Space.
Read more >
Programmatically Uploading Images, Videos, and Other Files
Learn how to upload images, videos, and other files with only a line or two of code - with cloud storage, CDN delivery,...
Read more >
Upload files to Firebase Storage using Node.js - Stack Overflow
You can find the bucket name in the Firebase web config object or in the Firebase Storage tab. Basically your code should start...
Read more >
Simple File Upload | Heroku Dev Center
Image uploading and resizing with a prebuilt S3 setup. ... to your app allows you to offload the storage of static files from...
Read more >
Vue Image Upload Made Easy - YouTube
Vue. js is a JavaScript framework that allows us to build highly engaging web apps. Uploading images (or file upload in general) is...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found