|
本帖最后由 worldpeace 于 2019-8-1 17:37 编辑
在手机选一个图片,然后用image.compressImage压缩完,都很快,,,
然后调用request.upload 上传这个压缩完的图片
要持续7,8秒才能上传完成...
getPic(type){
let me = this
let d = this
if(type == 'pick'){
media.pickImage({
success: function(data) {
compress(data.uri)
},
fail: function (data, code) {
console.log(`handling fail, code = ${code}`)
}
})
}else{
media.takePhoto({
success: function(data) {
compress(data.uri)
},
fail: function (data, code) {
console.log(`handling fail, code = ${code}`)
}
})
}
function compress(uri){
image.getImageInfo({
uri: uri,
success: function(data) {
console.log(`handling success: size = ${data.size}`)
let radioNum = (data.width / 600).toFixed(1)
d.debug.push(radioNum)
image.compressImage({
uri: uri,
quality: 90,
radio: radioNum, // 变为原图的1/2大小
format: 'JPEG',
success: function(compressData) {
d.debug.push("压缩完成:"+ compressData.uri)
me.uploadFile(compressData.uri)
},
fail: function(data, code) {
console.log(`handling fail, code = ${code}`)
}
})
},
fail: function(data, code) {
console.log(`handling fail, code = ${code}`)
}
})
}
},
uploadFile(file){
let me = this
let d = this
d.isShowPopSelect = false
d.isLoading = true
request.upload({
url: API.uploadPhotos,
method: 'POST',
files: [
{
uri: file,
filename: 'test.jpeg',
}
],
success: function(res) {
let rd = JSON.parse(res.data)
let errMsg = false
d.isLoading = false
let themeId = d.gender == 'female' ? 933 : 1232
if (rd.errorCode == 0 ) {
router.push ({
uri: '/Detail?sid='+ rd.photoSids[0]+ '&themeId='+themeId
})
}else{
d.isShowPopSelect = true
}
},
fail: function(data, code) {
d.isLoading = false
d.debug.push("data-fail")
console.log(`handling fail, code = ${code}`)
}
})
},
看看有什么问题吗
|
|