Why do I have error code 400 (bad request)?
I am trying to upload images to my linode storage using angular 16. I have the below code to do so:
export class UploadComponent {
fileSelected: any = null;
config = {
bucketName: 'cfe2',
region: 'ap-south-1',
accessKeyId: "my accessKeyId",
secretAccessKey: "my secretAccessKey",
s3Url: 'https://cfe2.ap-south-1.linodeobjects.com/'
}
S3CustomClient: AWSS3UploadAshClient = new AWSS3UploadAshClient(this.config);
constructor() { }
ngOnInit() {
}
onChangeFile(event: any) {
console.log(event.target.files[0])
this.fileSelected = event.target.files[0]
}
async handleSendFile() {
console.log("handleSendFile")
await this.S3CustomClient
.uploadFile(this.fileSelected, this.fileSelected.type, undefined,
this.fileSelected.name, "public-read")
.then((data: UploadResponse) => console.log(data))
.catch((err: any) => console.error(err))
}
}
and the html:
div class="content">
input (change)="onChangeFile($event)" type="file">
button type="button" (click)="handleSendFile()" >Send file
</div
1 Reply
400 Bad Requests errors generally signify that either your request is invalid or not permitted based on the information submitted within the request. Based on my understanding of our Object Storage API and how S3-compatible storage responds to requests from sources such as S3cmd, I would recommend verifying the following information as fully accurate:
- accessKeyId and secretAccessKey
- Bucket Name, Region, and S3URL (or Custom Domain Name)
- File Path and File Format
Do you have the full error message output? That may provide additional information about the precise reason your API call to your Object Storage bucket failed.