Question

How to solve forbidden error when uploading files to do spaces

I am trying to upload files in my flutter application using dospace and I have been getting this error message : flutter: DOException { statusCode: 403, reasonPhrase: “Forbidden”, responseBody: “<?xml version=“1.0” encoding=“UTF-8”?><Error><Code>InvalidAccessKeyId</Code><RequestId>tx0000000000000245603d7-0063457665-5c963c72-fra1b</RequestId><HostId>5c963c72-fra1b-fra1-zg02</HostId></Error>” }

This is my flutter code

 Future<void> uploadFileMethod() async {
    dospace.Spaces spaces = dospace.Spaces(
      //change with your project's region
      region: "fra1",

      //change with your project's accessKey
      accessKey: "*************",
      //change with your project's secretKey
      secretKey: "*****************************",
      endpointUrl: 'https://fra1.digitaloceanspaces.com',
    );
    try {
      var pickedFile;
      FilePickerResult? result = await FilePicker.platform.pickFiles();

      if (result != null) {
        File file = File(result.files.single.path as String);
        pickedFile = file;
      } else {
        // User canceled the picker
        return;
      }



      String projectName = "*******"; // change to projectname
      // change with your project's region
      String region = "fra1";
      // change with your project's folder
      String folderName = "videofiles";
      String fileName = pickedFile.path.split('/').last;

      String? etag = await spaces.bucket(projectName).uploadFile(
            "$folderName/$fileName",
            pickedFile,
            "image/jpg",
            dospace.Permissions.public,
          );
      print(etag);
     

      await spaces.close();
    } catch (error) {
      print(error);
    }
  }

Submit an answer


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

alexdo
Site Moderator
Site Moderator badge
October 12, 2022

Hello @jeromejumah

The first step will be to verify that the AccessKey is correct. You can also try to generate a new pair of secret and access key.

I’ve had a similar issue in the past but also my string for the endpoint was embedded two times and thus making the URL incorrect.

Regards

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up