<?xml version="1.0" encoding="UTF-8"?><Error><Code>InvalidRequest</Code><Message>Missing x-amz-conte

Hello, I'm trying to create a pre-signed URL with the S3 API, I followed the Cloudflare doc and my code looked like this:
import { Injectable, Scope } from '@nestjs/common';
import { getSignedUrl } from '@aws-sdk/s3-request-presigner';
import { DeleteFileProps, DownloadFileProps } from './types';
import { GetObjectCommand, DeleteObjectCommand, PutObjectCommand, S3Client } from '@aws-sdk/client-s3';
import { env } from 'src/constants/env';

@Injectable({ scope: Scope.REQUEST})
export class StorageService {
private readonly s3Client: S3Client;
constructor() {
this.s3Client = new S3Client({
region: 'auto',
endpoint: `https://${env.AWS_ACCOUNT_ID}.r2.cloudflarestorage.com`,
credentials: {
accessKeyId: env.AWS_ACCESS_KEY_ID,
secretAccessKey: env.AWS_SECRET_ACCESS_KEY,
}
});
}
async getUploadUrl({ bucket, path }: DownloadFileProps) {
const command = new PutObjectCommand({
Bucket: bucket,
Key: path,
ContentType: 'text/csv',
});
const url = await getSignedUrl(this.s3Client, command, { expiresIn: 60 * 5 });
return url;
}
}
import { Injectable, Scope } from '@nestjs/common';
import { getSignedUrl } from '@aws-sdk/s3-request-presigner';
import { DeleteFileProps, DownloadFileProps } from './types';
import { GetObjectCommand, DeleteObjectCommand, PutObjectCommand, S3Client } from '@aws-sdk/client-s3';
import { env } from 'src/constants/env';

@Injectable({ scope: Scope.REQUEST})
export class StorageService {
private readonly s3Client: S3Client;
constructor() {
this.s3Client = new S3Client({
region: 'auto',
endpoint: `https://${env.AWS_ACCOUNT_ID}.r2.cloudflarestorage.com`,
credentials: {
accessKeyId: env.AWS_ACCESS_KEY_ID,
secretAccessKey: env.AWS_SECRET_ACCESS_KEY,
}
});
}
async getUploadUrl({ bucket, path }: DownloadFileProps) {
const command = new PutObjectCommand({
Bucket: bucket,
Key: path,
ContentType: 'text/csv',
});
const url = await getSignedUrl(this.s3Client, command, { expiresIn: 60 * 5 });
return url;
}
}
The url is generated normally, but when trying to upload the file it gives this error "<?xml version="1.0" encoding="UTF-8"?><Error><Code>InvalidRequest</Code><Message>Missing x-amz-content-sha256</Message></Error>" I'm making the request in Postman, with the PUT method, and the file in the body through the "binary" tab
1 Reply
Flare
Flare•6mo ago
Please do not post your question in multiple channels per the rules at #😃welcome-and-rules. It creates confusion for people trying to help you and doesn't get your issue or question solved any faster.
Want results from more Discord servers?
Add your server