提交 11d04cca 编写于 作者: D dolymood

upload support action checkSuccess option

上级 dddedd2b
...@@ -31,7 +31,11 @@ ...@@ -31,7 +31,11 @@
action: '//jsonplaceholder.typicode.com/photos/', action: '//jsonplaceholder.typicode.com/photos/',
action2: { action2: {
target: '//jsonplaceholder.typicode.com/photos/', target: '//jsonplaceholder.typicode.com/photos/',
prop: 'base64Value' prop: 'base64Value',
checkSuccess(res) {
// success
return true
}
}, },
isUploading: true isUploading: true
} }
......
...@@ -13,7 +13,8 @@ export default function ajaxUpload(file, options, changeHandler) { ...@@ -13,7 +13,8 @@ export default function ajaxUpload(file, options, changeHandler) {
withCredentials, withCredentials,
timeout, timeout,
prop = 'file', prop = 'file',
progressInterval = 100 progressInterval = 100,
checkSuccess = function () { return true }
} = options } = options
file.progress = 0 file.progress = 0
...@@ -65,7 +66,9 @@ export default function ajaxUpload(file, options, changeHandler) { ...@@ -65,7 +66,9 @@ export default function ajaxUpload(file, options, changeHandler) {
} catch (e) {} } catch (e) {}
file.response = response file.response = response
file.responseHeaders = xhr.getAllResponseHeaders() file.responseHeaders = xhr.getAllResponseHeaders()
setStatus(STATUS_SUCCESS)
const isSuccess = checkSuccess(response)
setStatus(isSuccess ? STATUS_SUCCESS : STATUS_ERROR)
} }
xhr.onerror = function () { xhr.onerror = function () {
setStatus(STATUS_ERROR) setStatus(STATUS_ERROR)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册