DeveloperApps
DeveloperApps

Reputation: 803

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

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);
            });
        }
      });
  };

Upvotes: 0

Views: 881

Answers (1)

Mark B
Mark B

Reputation: 200562

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

Upvotes: 1

Related Questions