Python Forum
REST API send_file decode64?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
REST API send_file decode64?
#1
Hello ,
I have created a RESTAPI server using Flask that send me a file by request
ZipLocation = '/home/pi/logs/Data.zip'
return send_file(str(ZipLocation), as_attachment=True)
everything work and I get a working ZIP file

now I need also to upload the file as base64

I have try many thing
 
        try:
            with open(str(ZipLocation), 'rb') as files:
                encodeFile = base64.b64encode(files)
          
        except Exception as e:
            print(e)
        else:
            return send_file(attachment_filename=encodeFile)
but it doesn't work
I get this error

a bytes-like object is required, not '_io.BufferedReader'
have also try this
try:
            test = request.files[str(ZipLocation)]
                encodeFile = base64.b64encode(test.read())
            except Exception as e:
                print( e)
        else:
            return send_file(attachment_filename=encodeFile, as_attachment=True)
and here I'm getting :
400 Bad Request: The browser (or proxy) sent a request that this server could not understand.
what did I do wrong? missing ?

Thanks ,
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020