PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, November 8, 2022

[FIXED] How to set ACL to public-read when adding a file to S3 or DigitalOcean

 November 08, 2022     amazon-s3, amazon-web-services, digital-ocean, reactjs     No comments   

Issue

I have a function that adds a file to Digital Ocean Spaces.

Files are Private by default. I want the files to be public for reading.

I added "x-amz-acl": "public-read" in headers to get public files.

This solution does not work. The API does not accept and returns the SignatureDoesNotMatch error.

There is nothing in the documentation about this. I perform the action through axios as a pure REST API

const uploadInvitationImage = () => {
    axios
      .get(general.apiUrl + "api/aws/uploadUrl/" + name + ".png", {
        headers: headers,
      })
      .then((response) => {
        if (response.status == 200) {
          const uploadUrl = response.data;
          axios({
            method: "PUT",
            url: uploadUrl,
            data: fileImage,
            headers: {
              "Content-Type": "image/png",
              "x-amz-acl": "public-read",
            },
          })
            .then((res) => {
              setFileImage(null);
            })
            .catch((err) => {
              console.log(err);
            });
        }
      });
  };

Solution

The API you are calling at "api/aws/uploadUrl/" needs to add those to the URL it generates, before it signs the URL.



Answered By - Mark B
Answer Checked By - Katrina (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing