blob-upload-1_1.py 982 B

1234567891011121314151617181920212223242526272829
  1. def upload_file():
  2. if request.method == 'POST':
  3. file = request.files['file']
  4. filename = secure_filename(file.filename)
  5. fileextension = filename.rsplit('.',1)[1]
  6. Randomfilename = id_generator()
  7. filename = Randomfilename + '.' + fileextension
  8. try:
  9. blob_service.create_blob_from_stream(container, filename, file)
  10. except Exception:
  11. print ('Exception=' + Exception)
  12. pass
  13. ref = 'http://'+ account + '.blob.core.windows.net/' + container + '/' + filename
  14. return '''
  15. <!doctype html>
  16. <title>File Link</title>
  17. <h1>Uploaded File Link</h1>
  18. <p>''' + ref + '''</p>
  19. <img src="'''+ ref +'''">
  20. '''
  21. return '''
  22. <!doctype html>
  23. <title>Upload new File</title>
  24. <h1>Upload new File</h1>
  25. <form action="" method=post enctype=multipart/form-data>
  26. <p><input type=file name=file>
  27. <input type=submit value=Upload>
  28. </form>
  29. '''