|
@@ -4,6 +4,7 @@ const app = getApp()
|
|
const API = app.globalData.api
|
|
const API = app.globalData.api
|
|
const SUFFIX = ["jpg", "jpeg", "png"]
|
|
const SUFFIX = ["jpg", "jpeg", "png"]
|
|
const MASK = false
|
|
const MASK = false
|
|
|
|
+const MD5 = require('js-md5')
|
|
Component({
|
|
Component({
|
|
/**
|
|
/**
|
|
* 组件的属性列表
|
|
* 组件的属性列表
|
|
@@ -33,6 +34,7 @@ Component({
|
|
enableChoose: true,
|
|
enableChoose: true,
|
|
gridLoading: false,
|
|
gridLoading: false,
|
|
willSubmit: false, // 确定按钮是否已点击
|
|
willSubmit: false, // 确定按钮是否已点击
|
|
|
|
+ mmd: MD5
|
|
},
|
|
},
|
|
|
|
|
|
timeoutHandler: null,
|
|
timeoutHandler: null,
|
|
@@ -376,9 +378,23 @@ Component({
|
|
}
|
|
}
|
|
},
|
|
},
|
|
|
|
|
|
|
|
+ uploadFail(that, filepath, md5, formParams, formUrl, accessUrl, index, retry) {
|
|
|
|
+ var pic = that.data.pictures
|
|
|
|
+ pic[index]['status'] = 'FAIL'
|
|
|
|
+ pic[index]['retry'] = 3 - retry
|
|
|
|
+ that.setData({
|
|
|
|
+ pictures: pic
|
|
|
|
+ })
|
|
|
|
+ that.checkFailed()
|
|
|
|
+ retry--
|
|
|
|
+ if (retry > 0) {
|
|
|
|
+ that.uploadFile(filepath, md5, formParams, md5, formUrl, accessUrl, index, retry)
|
|
|
|
+ }
|
|
|
|
+ },
|
|
|
|
+
|
|
//上传文件,支持配置重试次数
|
|
//上传文件,支持配置重试次数
|
|
- uploadFile(filepath, formParams, formUrl, accessUrl, index, retry) {
|
|
|
|
- console.log('uploadFile:cancelAll', this.data.cancelAll)
|
|
|
|
|
|
+ uploadFile(filepath, md5, formParams, formUrl, accessUrl, index, retry) {
|
|
|
|
+ console.log('uploadFile')
|
|
if (this.data.cancelAll) {
|
|
if (this.data.cancelAll) {
|
|
return
|
|
return
|
|
}
|
|
}
|
|
@@ -386,26 +402,35 @@ Component({
|
|
return
|
|
return
|
|
}
|
|
}
|
|
const that = this
|
|
const that = this
|
|
- API.uploadFile(filepath, formParams, formUrl).then(res => {
|
|
|
|
- var pic = that.data.pictures
|
|
|
|
- pic[index]['url'] = accessUrl
|
|
|
|
- pic[index]['status'] = 'SUCCESS'
|
|
|
|
- that.setData({
|
|
|
|
- pictures: pic
|
|
|
|
- })
|
|
|
|
- that.checkUploadComplete()
|
|
|
|
- }).catch(exceptions => {
|
|
|
|
- console.log('uploadFile:uploadFile:catch', exceptions)
|
|
|
|
- var pic = that.data.pictures
|
|
|
|
- pic[index]['status'] = 'FAIL'
|
|
|
|
- pic[index]['retry'] = 3 - retry
|
|
|
|
- that.setData({
|
|
|
|
- pictures: pic
|
|
|
|
- })
|
|
|
|
- that.checkFailed()
|
|
|
|
- retry--
|
|
|
|
- if (retry > 0) {
|
|
|
|
- that.uploadFile(filepath, formParams, formUrl, accessUrl, index, retry)
|
|
|
|
|
|
+
|
|
|
|
+ const c_md5 = wx.arrayBufferToBase64(new Uint8Array(md5.match(/[\da-f]{2}/gi).map(function (h) {
|
|
|
|
+ return parseInt(h, 16)
|
|
|
|
+ })))
|
|
|
|
+ console.log('uploadFile::start upload')
|
|
|
|
+ const task = wx.uploadFile({
|
|
|
|
+ url: formUrl,
|
|
|
|
+ filePath: filepath,
|
|
|
|
+ name: 'file',
|
|
|
|
+ formData: formParams,
|
|
|
|
+ success: taskRes => {
|
|
|
|
+ console.log('uploadFile::upload success', taskRes)
|
|
|
|
+ var pic = that.data.pictures
|
|
|
|
+ pic[index]['url'] = accessUrl
|
|
|
|
+ pic[index]['status'] = 'SUCCESS'
|
|
|
|
+ that.setData({
|
|
|
|
+ pictures: pic
|
|
|
|
+ })
|
|
|
|
+ that.checkUploadComplete()
|
|
|
|
+ },
|
|
|
|
+ fail: error => {
|
|
|
|
+ console.log('uploadFile:uploadFile:catch', error)
|
|
|
|
+ that.uploadFail(that, filepath, md5, formParams, formUrl, accessUrl, index, retry)
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+ task.onHeadersReceived(res => {
|
|
|
|
+ console.log('task header::', res, res.header['Content-MD5'], c_md5)
|
|
|
|
+ if (c_md5 != res.header['Content-MD5']) {
|
|
|
|
+ that.uploadFail(that, filepath, md5, formParams, formUrl, accessUrl, index, retry)
|
|
}
|
|
}
|
|
})
|
|
})
|
|
},
|
|
},
|
|
@@ -427,15 +452,15 @@ Component({
|
|
console.log('uploadImage:compressImage:success',cf)
|
|
console.log('uploadImage:compressImage:success',cf)
|
|
wx.getFileInfo({
|
|
wx.getFileInfo({
|
|
filePath: cf.tempFilePath,
|
|
filePath: cf.tempFilePath,
|
|
- success: function (res) {
|
|
|
|
- console.log('uploadImage:compressImage:success>>getFileInfo:success', res)
|
|
|
|
|
|
+ success: function (fileRes) {
|
|
|
|
+ console.log('uploadImage:compressImage:success>>getFileInfo:success', fileRes)
|
|
// 获取上传签名
|
|
// 获取上传签名
|
|
API.getSign(that.data.paper.examRecordDataId, that.data.paper.examStudentId,
|
|
API.getSign(that.data.paper.examRecordDataId, that.data.paper.examStudentId,
|
|
- that.data.paper.questionOrder, res.digest, 'jpeg')
|
|
|
|
|
|
+ that.data.paper.questionOrder, fileRes.digest, 'jpeg')
|
|
.then(signResult => {
|
|
.then(signResult => {
|
|
// 上传文件
|
|
// 上传文件
|
|
var _retry = 3
|
|
var _retry = 3
|
|
- that.uploadFile(cf.tempFilePath, signResult.formParams, signResult.formUrl, signResult.accessUrl, imageIndex, _retry)
|
|
|
|
|
|
+ that.uploadFile(cf.tempFilePath, fileRes.digest, signResult.formParams, signResult.formUrl, signResult.accessUrl, imageIndex, _retry)
|
|
}).catch(exceptions => {
|
|
}).catch(exceptions => {
|
|
var pic = that.data.pictures
|
|
var pic = that.data.pictures
|
|
pic[imageIndex]['status'] = 'FAIL'
|
|
pic[imageIndex]['status'] = 'FAIL'
|
|
@@ -444,7 +469,7 @@ Component({
|
|
pictures: pic
|
|
pictures: pic
|
|
})
|
|
})
|
|
that.checkFailed()
|
|
that.checkFailed()
|
|
- console.log('uploadImage:exceptions:', new Date(), pic)
|
|
|
|
|
|
+ console.log('uploadImage:exceptions:', new Date(), pic, exceptions)
|
|
that.uploadImage(imageIndex, --retry)
|
|
that.uploadImage(imageIndex, --retry)
|
|
})
|
|
})
|
|
}
|
|
}
|