I've been trying to learn JavaScript and I'm completely stuck on an issue. I've been working on a project using Supabase for storage, but I'm getting an HTTP 400 error and can't figure out what I'm doing wrong. I've double-checked the variable names, and the error is driving me insane. Here's the relevant part of my code where I'm trying to upload an image from a virtual wardrobe app:
```javascript
class Wardrobe {
constructor(id) {
this.id = document.getElementById(id);
this.render();
this.supabase = supabase.createClient("project_url","project_key");
this.bindEvents();
}
render() {
this.id.innerHTML = `
Virtual Wardrobe
`;
}
bindEvents() {
document.getElementById("add-shirt").onclick = () => this.addItem("shirt");
document.getElementById("add-pants").onclick = () => this.addItem("pants");
document.getElementById("add-shoes").onclick = () => this.addItem("shoes");
}
get_image(data) {
const data_input = document.getElementById(data);
if (!data_input) return null;
return data_input.files[0];
}
async addItem(type) {
const img = this.get_image("image_data");
if (!img) {
alert(`No file selected`);
return;
}
const {data, error} = await this.supabase
.storage
.from("wardrobe")
.upload(`image/testing.jpg`, img);
}
}
new Wardrobe("app");
```
Can anyone help me understand what's wrong?
3 Answers
Inspecting the HTTP message is key. If you can't figure out the issue, pay close attention to the API documentation for the endpoint you're trying to reach. It should tell you what's going wrong with your request. It might lead you to where your code is misconfigured.
First off, have you checked the developer tools in your browser? Press F12 to see the network requests made. That way, you can look at the request and response details. Sometimes you'll find hints about what the bad request might be due to – like missing fields or incorrect formatting. Also, consult the Supabase API documentation to check if you're following the right rules for uploads.
Just to add to that, an HTTP 400 error means your request is malformed. Double-check that you're following the guidelines in the API docs for the upload process. Each platform can have specific requirements that, if not followed, will result in these kinds of errors.

Related Questions
How To: Running Codex CLI on Windows with Azure OpenAI
Set Wordpress Featured Image Using Javascript
How To Fix PHP Random Being The Same
Why no WebP Support with Wordpress
Replace Wordpress Cron With Linux Cron
Customize Yoast Canonical URL Programmatically