文件操作基础
import upyun
# 新建又拍云实例
up = upyun.UpYun('md233',username='wangrui',password='7Ly7NfX30PQ63GyPFIlSIHiQ2QRWQz76')
# 上传文件
up.put('/upyun_test.text','afsdfsdfds\n你好你好你好\n')
# 文件流操作(节省内存)
with open('./md.png','rb')as f:
# 上传操作
res = up.put('/upyun_test.png',f,checksum=True)
# 目录操作
up.mkdir('/upyun_test/')
# 移动文件
up.move('/upyun_test.png','/upyun_test/upyun_test.png')
# 复制文件
up.copy('/upyun_test.text','/upyun_test/upyun_test1.txt')
# 断点续传
with open('E:/阅卷视屏.mp4','rb') as f:
res = up.put('/upyun/test.mp4',f,checksum=True)
# 下载文件
res = up.get('/upyun_test/upyun_test.png')
# 删除文件
up.delete('/upyun_test/upyun_test.png')
又拍云项目实践
class Del(APIView):
def get(self,request):
# 接收参数
name = request.GET.get('name',None)
up = upyun.UpYun('md233',username='wangrui',password='7Ly7NfX30PQ63GyPFIlSIHiQ2QRWQz76')
up.delete(name)
return Response({'code':200,'img':'删除成功'})
class Chuangjian(APIView):
# 创建目录
def get(self,request):
uid = request.GET.get('uid')
dirname = request.GET.get('dirname')
up = upyun.UpYun('md233',username='wangrui',password='7Ly7NfX30PQ63GyPFIlSIHiQ2QRWQz76')
up.mkdir('/%s/'%dirname)
return Response({'msg': '创建成功'})
<div>
<img :src="src" >
<Avatar :src="src" :width="150" fit="fill"></Avatar>
<br />
<Button color="red" @click="del_Avatar">删除</Button>
  
<input type="text" /><Button color="blue" @click="newdir">创建目录</Button>
</div>
//新建文件夹
newdir(){
var uid = localStorage.getItem("uid");
this.axios.get("http://127.0.0.1:8000/chuang/", {
params: { 'uid': uid,'dirname':this.dirname}
}).then(result => {
console.log(result.data)
})
},
// 删除头像操作
del_Avatar:function(){
this.axios.get("http://127.0.0.1:8000/del/",{params:{'name':this.yp_name}}).then(res=>{
console.log(res)
})
}