Home > database >  Starlette - Type Error: FormData object is not callable
Starlette - Type Error: FormData object is not callable

Time:11-16

I'm uploading an audio file to a Starlette server and I'm trying to access it the way they recommend in the docs, but it's giving me a not callable error. I gather the issue is calling .form() on the request object, but I'm not sure how else to read it in.

Server Route:

@app.route('/api/upload_track/', methods=['POST'])
async def separate_vocals(request):
    audio_data = await request.form()
    separator = Separator('spleeter:2stems')
    audio_bytes = await (audio_data['file'].read())
    return audio_data

Client:

function FileUploadSingle() {
  const [file, setFile] = useState([]);

  const handleFileChange = (e) => {
    if (e.target.files) {
      setFile(e.target.files[0]);
    }
  };
   
    let audioData = new FormData();

    const blob = new Blob([file], {type: 'audio/mpeg'});
    audioData.append('file', file, 'file');
    console.log(file);
    console.log(audioData.get('file'));
    //            
  • Related