Convert image to base64 before sending Item to sync
This commit is contained in:
parent
057839298c
commit
a12076e0fd
@ -0,0 +1,19 @@
|
||||
import io, base64, urllib, os
|
||||
|
||||
def pre_process(doc):
|
||||
|
||||
file_path = doc.image
|
||||
file_name = os.path.basename(file_path)
|
||||
|
||||
if file_path.startswith('http'):
|
||||
url = file_path
|
||||
file_path = os.path.join('/tmp', file_name)
|
||||
urllib.urlretrieve(url, file_path)
|
||||
|
||||
with io.open(file_path, 'rb') as f:
|
||||
doc.image = base64.b64encode(f.read())
|
||||
|
||||
doc.image_file_name = file_name
|
||||
|
||||
return doc
|
||||
|
Loading…
x
Reference in New Issue
Block a user