I am trying to upload an image to cloudinary from the client side. I have created a Form Data and I am trying to pass that but it comes back empty.
The HTML:
<div class="my-2">
<input
id="image"
ref="image"
type="file"
class="inputfile img"
name="image"
aria-describedby="imageFile"
accept="image/*"
@change="addImage"
/>
<label for="image">
<span>{{ fileName }}</span>
<strong><i class="fas fa-upload"></i> Choose an Image…</strong>
</label>
</div>
The addImage function thats called:
async addImage(image) {
try {
this.$emit('input', image.target.files[0]);
this.photo = this.$refs.image.files[0];
this.photoName = this.photo.name;
const formData = new FormData();
formData.append('file', this.photo, this.photo.name);
const upload = await this.$cloudinary.upload(formData, {
upload_preset: 'jj4vb6nq',
});
} catch (e) {
console.error(e.message);
// this.error = e.message;
}
},
When it attempts to upload I get the following error:
{
"message": "Invalid file parameter. Make sure your file parameter does not include '[]'"
}
Is there a better way to upload the image?
this.photo = image.target.files[0]
– DarioRega