Skip to content
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

Check file type from request data #77

Open
Winedays opened this issue Sep 17, 2020 · 1 comment
Open

Check file type from request data #77

Winedays opened this issue Sep 17, 2020 · 1 comment

Comments

@Winedays
Copy link

I am trying to get the file type from request data and save it, but the saved file can't use if I call filetype.guess( audio_file ).

I also try to save the data first, read the saved file and save again after i checked the file type, the saved file can't use too.

how to I solved this problem?

  • get the file type from request data and save it
audio_file = request.files['data']
kind = filetype.guess( audio_file )

if kind is not None :
    file_type = kind.extension
    wav_path = os.path.join( current_app.config['UPLOAD_FOLDER'], 'audio.'+file_type )
  • save the data first, read it and save again
audio_file = request.files['data']
tmp_path = os.path.join( current_app.config['UPLOAD_FOLDER'], "upload_audio.tmp" )
audio_file.save( tmp_path )

tmp_file = open( tmp_path , 'rb' )
tmp_data = tmp_file.read()
kind = filetype.guess( tmp_data )
tmp_file.close()

if kind is not None :
    file_type = kind.extension
    wav_path = os.path.join( current_app.config['UPLOAD_FOLDER'], wav_id+'.'+file_type )
    wav_file = open( wav_path , 'wb' )
    wav_file.write( tmp_data )
    wav_file.close()
@dosas
Copy link

dosas commented Dec 20, 2020

@Winedays Do you have an example url?
I did not get your problem. Are you unable to check the file type or unable to play the audio file?

Have you had a look here? #62 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants