blob-upload-3_3.py 929 B

123456789101112131415161718
  1. def upldfile():
  2. if request.method == 'POST':
  3. file = request.files['file']
  4. if file and allowed_file(file.filename):
  5. filename = secure_filename(file.filename)
  6. app.logger.info('FileName: ' + filename)
  7. block_blob_service = BlockBlobService(account_name=app.config['AZURE_STORAGE_ACCOUNT'], account_key=app.config['AZURE_STORAGE_KEY'])
  8. block_blob_service.create_blob_from_bytes(
  9. 'doc',
  10. filename,
  11. file.read())
  12. # updir = os.path.join(basedir, 'upload/')
  13. # file.save(os.path.join(updir, filename))
  14. # file_size = os.path.getsize(os.path.join(updir, filename))
  15. return jsonify(name=filename, url='https://'+app.config['AZURE_STORAGE_ACCOUNT']+'.blob.core.windows.net/' \
  16. +app.config['AZURE_STORAGE_CONTAINER']+'/'+filename)