Skip to content

image validation added for creating blog #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/components/CreateBlog.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,20 @@ const CreateBlog = () => {
function onChange(e) {
setHtml(e.target.value);
}



const handleFileChange = async (e) => {
const file = e.target.files[0];

// if (!file) return;

// Check for file type and size
if (!file.type.startsWith('image/') || file.size > 5000000) { // 5MB limit
alert('Invalid file. Please upload a valid image under 5MB.');
e.target.value = null;
return;
}
const formData = new FormData();
formData.append("image", file);

Expand Down Expand Up @@ -46,6 +57,7 @@ const CreateBlog = () => {
description: html,
image_id: imageId // Adjusted to match backend variable
};


try {
const res = await fetch("http://localhost:8000/api/blogs", {
Expand Down