Cant upload files to DO space with Signed Urls.

-----------------BACK-END - CONFIG FILE---------------

import aws from 'aws-sdk'
import { authConfig } from '../appConfig/auth'

const regionName = authConfig.FILE_STORAGE.DO_FILES_REGION-----> //sgp1
const spacesEndpoint = new aws.Endpoint(`${regionName}`)

const doS3Client = new aws.S3({
  endpoint: spacesEndpoint,
  accessKeyId: authConfig.FILE_STORAGE.DO_FILES_KEY,
  secretAccessKey: authConfig.FILE_STORAGE.DO_FILES_REGION,
  region: authConfig.FILE_STORAGE.DO_FILES_REGION,
  signatureVersion: 'v4',

export { doS3Client }

--------------BACK-END - SIGNED URL GENERATION------------

const s3Params = {
  Bucket: DOBucket,
  Key: data[i]?.fileName,
  ContentType: data[i]?.fileType,
  ACL: 'public-read',
  Expires: 60,

const signedRequest = await doS3Client.getSignedUrl('putObject', s3Params)


const uploadToDOSpaces = async (data: FileUploadInput[], signedUrls: any) => {

console.log('--signedUrls--', signedUrls[0].signedRequest);
console.log('--data--', data[0].file);
console.log('--data--', data[0].fileType);

Signed url

File to Upload

File Type

    try {
      for (let i = 0; i < data.length; i++) {
        await fetch(signedUrls[i].signedRequest, {
          headers: {
            'Content-Type': data[i].fileType,
            'Cache-Control': 'public,max-age=31536000,immutable',
            'x-amz-acl': 'public-read',
          method: 'PUT',
          body: await upload(data[i].file),
    } catch (error) {
      console.log('error', error);

const upload = (file: string): any => {
    try {
      return new Promise((resolve, reject) => {
        const xhr = new XMLHttpRequest();
        xhr.onerror = reject;
        xhr.onreadystatechange = () => {
          if (xhr.readyState === 4) {
        };'GET', file);
        xhr.responseType = 'blob'; // convert type
        xhr.setRequestHeader('x-amz-acl', 'public-read');
    } catch (error) {
      console.log('error', 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.

the upload xhr request in your upload function is incorrect. Signed urls should be sent as a put request not a get request.

Try DigitalOcean for free

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

Sign up

card icon
Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Sign up
card icon
Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We’d like to help.

Learn more
card icon
Become a contributor

You get paid; we donate to tech nonprofits.

Learn more
Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow – whether you’re running one virtual machine or ten thousand.

Learn more ->
DigitalOcean Cloud Control Panel
Get started for free

Enter your email to get $200 in credit for your first 60 days with DigitalOcean.

New accounts only. By submitting your email you agree to our Privacy Policy.

© 2023 DigitalOcean, LLC.