uniapp图片上传

			   _self = this;
					   uni.chooseImage({
					    count: 1,
					    sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
					    sourceType: ['album'], //从相册选择
					    success: function (res) {
					     const tempFilePaths = res.tempFilePaths;
						 console.log(3333, res.tempFilePaths[0])
					     const uploadTask = uni.uploadFile({
					       url: 'xxxxx',
					      filePath: tempFilePaths[0],
					      fileType:"image",
						  name:"upfile",
					      formData: {
					      
						   "taskId":24,
						 
					      },
						  header:{
							  token:"xxxxxxxxx"
						  },
					      success: function (uploadFileRes) {
					       console.log(66666666666666,uploadFileRes);
					      }
					     });
					 
					     uploadTask.onProgressUpdate(function (res) {
					      _self.percent = res.progress;
					      console.log('上传进度' + res.progress);
					      console.log('已经上传的数据长度' + res.totalBytesSent);
					      console.log('预期需要上传的数据总长度' + res.totalBytesExpectedToSend);
					     });
					    },
					    error : function(e){
					     console.log(e);
					    }
					   });

 

你可能感兴趣的:(vue基础知识总结)