Last active
March 17, 2019 13:24
-
-
Save includeamin/e42c1c5ff3467c570aaff4119267d750 to your computer and use it in GitHub Desktop.
upload file in json Flask
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def upload_image_from_base64(encoded, item, value, filename): | |
if str(item).lower() == "profile": | |
with open(get_user_profile_dir(value, filename), "wb") as fh: | |
temp = str(encoded).encode('utf-8') | |
temp = base64.b64decode(temp) | |
fh.write(base64.b64decode(temp)) | |
return True | |
return False | |
def update_user_profile(): | |
token = {"Token":"***", | |
"Phonenumber":'****'} | |
content =requests.post("http://localhost:3002/users/profile/update",headers=token,json={"Fname":'amin', | |
'Lname':'jamal', | |
'Birthday':'1,1,1996', | |
'Email':'[email protected]', | |
"Profile":filetobase64()}).content | |
print(json.loads(content)) | |
def filetobase64(): | |
with open("1.jpg", "rb") as image_file: | |
encoded_string = base64.b64encode(image_file.read()) | |
base64_bytes = base64.b64encode(encoded_string) | |
base64_string = base64_bytes.decode('utf-8') | |
print(base64_string) | |
return base64_string |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment