Is it possible to upload document from a url?

I’m using python3 with AWS Lambda to try to upload documents when creating a business verified customer, but my current Lambda code just times out every time and I’m not sure why (have it set to run for 5 minutes, so I don’t believe it should take this long if it was working). When a customer uploads the document on our website, it is saved to our server, then Lambda needs to pull it into the /tmp folder in order to upload to Dwolla. Is there any way around this, such as by using the direct url to the file when sending to Dwolla, or is there a better way to handle this altogether?

Here is my current code in case it’s helpful:

customerUrl = data[‘customerUrl’]
docType = data[‘docType’]
fileUrl = data[‘fileUrl’]
http = urllib3.PoolManager()
r = http.request(‘GET’, fileUrl, preload_content=False)
with open(’/tmp/doc.png’, ‘wb’) as out: # set the extension based on the actual file
while True:
data = r.read(65536) # chunk size
if data is None:
break
out.write(data)
r.release_conn()
docTypeTranslation = {‘Passport’: ‘passport’, ‘Driver License’: ‘license’, ‘Other ID Card’: ‘idCard’, ‘Business Document’: ‘other’}
dwollaDoctype = docTypeTranslation[docType]
document = app_token.post(’%s/documents’ % customerUrl, file = open(’/tmp/doc.png’, ‘rb’), documentType = dwollaDoctype)

There was an error in my code. Just in case it’s helpful to anyone else, “if data is None:” should read “if not data:” otherwise it never stops running.

Hi @josh1 – thanks for the update!

As for your second question, I’m afraid the file contents have to be POSTed directly to the API.