-
Notifications
You must be signed in to change notification settings - Fork 46
Open
Description
I've followed the guide on the Inertia site and I've tried a few things. I don't think Django-inertia is handling file uploads properly as I can never see the content on the server side in request.FILES.
Here is my example React code:
import React from 'react';
import { useForm } from '@inertiajs/react';
export default function FileUploader() {
const { post } = useForm();
const handleFileUpload = (e) => {
const file = e.target.files[0];
if (!file) return;
const formData = new FormData();
formData.append('archimate_file', file);
post('/projects/upload', formData, {
forceFormData: true,
onSuccess: () => {
alert('Upload successful');
e.target.value = ''; // reset input
},
onError: (errors) => {
console.error('Upload error:', errors);
},
});
};
return (
<div>
<label className="cursor-pointer bg-blue-600 hover:bg-blue-700 text-white px-4 py-2 rounded">
Upload Archimate File
<input
type="file"
accept=".archimate"
onChange={handleFileUpload}
className="hidden"
/>
</label>
</div>
);
}
In Django:
views.py
@login_required
@require_http_methods(["POST"])
def upload_archimate_project(request):
if 'archimate_file' not in request.FILES:
print("Files in request:", request.FILES)
print("POST data:", request.POST)
return JsonResponse({'error': 'No file uploaded'}, status=400)
Metadata
Metadata
Assignees
Labels
No labels