I have an API call that currently utilizes a file upload. I’ve been able to successfully save a local copy of the file when the file extension is a .json. However, if I try to upload a .xml file, I get a ‘ERR I/O operation on closed file.’ I can’t seem to find a way to save off this uploaded .xml file. Is there special handling I need to do for this to work?
Currently, when passing the file upload from my frontend, I’m using fetch with a formData field where the file is coming from an html input element, like so:
<input
type="file"
ref={fileInput}
className="form-control"
name="file"
aria-describedby="inputGroupFileAddon04"
aria-label="Upload"
accept=".json, .xml"
defaultValue={uploadFile}
required
onChange={handleData}
/>
In my django backend, I’m attempting to save like so:
uploaded_file = request.FILES["file"]
fs = FileSystemStorage()
new_name = fs.save(uploaded_file.name, uploaded_file)
This method is working great for my .json file, but breaks for .xml. Anyone know why this would be happening or what I can do to allow loading an xml??