Home  >  Q&A  >  body text

python - django上传图片文件到七牛

是前端用户type=file那样上传图片文件。
我执行ret, info = put_file(token, key, localfile)
老是说localfile没有这个文件,但换成路径的时候,就能上传。谢谢了

伊谢尔伦伊谢尔伦2765 days ago874

reply all(2)I'll reply

  • PHP中文网

    PHP中文网2017-04-18 09:21:01

    key = 'my-python-logo.png';
    
    #上传文件到七牛后, 七牛将文件名和文件大小回调给业务服务器。
    policy={
     'callbackUrl':'http://your.domain.com/callback.php',
     'callbackBody':'filename=$(fname)&filesize=$(fsize)'
     }
    
    token = q.upload_token(bucket_name, key, 3600, policy)
    
    localfile = './sync/bbb.jpg'
    
    ret, info = put_file(token, key, localfile)
    print(info)
    assert ret['key'] == key
    assert ret['hash'] == etag(localfile)
    
    

    I don’t quite understand what you are talking about. Can you give me the values ​​​​of key and localfile?
    First of all, make sure you have not passed the key and localfile backwards.

    reply
    0
  • 高洛峰

    高洛峰2017-04-18 09:21:01

    You can try django-qiniu-storage

    reply
    0
  • Cancelreply