Report this

What is the reason for this report?

How to solve forbidden error when uploading files to do spaces

Posted on October 11, 2022

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


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!

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.

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

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.