File tree Expand file tree Collapse file tree 2 files changed +51
-1
lines changed Expand file tree Collapse file tree 2 files changed +51
-1
lines changed Original file line number Diff line number Diff line change @@ -123,7 +123,7 @@ class AjaxUploader extends Component<UploadProps> {
123
123
* Process file before upload. When all the file is ready, we start upload.
124
124
*/
125
125
processFile = async ( file : RcFile , fileList : RcFile [ ] ) : Promise < ParsedFileInfo > => {
126
- const { beforeUpload, action , data } = this . props ;
126
+ const { beforeUpload } = this . props ;
127
127
128
128
let transformedFile : BeforeUploadFileType | void = file ;
129
129
if ( beforeUpload ) {
@@ -143,6 +143,9 @@ class AjaxUploader extends Component<UploadProps> {
143
143
}
144
144
}
145
145
146
+ // Call beforeUpload could change action & data.
147
+ const { action, data } = this . props ;
148
+
146
149
let mergedAction : string ;
147
150
if ( typeof action === 'function' ) {
148
151
mergedAction = await action ( file ) ;
Original file line number Diff line number Diff line change @@ -393,6 +393,53 @@ describe('uploader', () => {
393
393
} ) ;
394
394
} ) ;
395
395
396
+ describe ( 'change action & data in beforeUpload' , ( ) => {
397
+ const files = [
398
+ {
399
+ name : 'success.png' ,
400
+ toString ( ) {
401
+ return this . name ;
402
+ } ,
403
+ } ,
404
+ ] ;
405
+
406
+ files . item = i => files [ i ] ;
407
+
408
+ it ( 'get changed value in customRequest' , done => {
409
+ const changedAction = '/test2' ;
410
+ const changedData = { b : 2 } ;
411
+
412
+ const Demo = ( ) => {
413
+ const [ action , setAction ] = React . useState ( '/test1' ) ;
414
+ const [ data , setData ] = React . useState ( { a : 1 } ) ;
415
+
416
+ return (
417
+ < Uploader
418
+ action = { action }
419
+ data = { data }
420
+ beforeUpload = { ( ) => {
421
+ setAction ( changedAction ) ;
422
+ setData ( changedData ) ;
423
+
424
+ return true ;
425
+ } }
426
+ customRequest = { options => {
427
+ expect ( options . action ) . toEqual ( changedAction ) ;
428
+ expect ( options . data ) . toEqual ( changedData ) ;
429
+
430
+ done ( ) ;
431
+ } }
432
+ />
433
+ ) ;
434
+ } ;
435
+
436
+ const wrapper = mount ( < Demo /> ) ;
437
+ const input = wrapper . find ( 'input' ) . first ( ) ;
438
+
439
+ input . simulate ( 'change' , { target : { files } } ) ;
440
+ } ) ;
441
+ } ) ;
442
+
396
443
describe ( 'transform file before request' , ( ) => {
397
444
let uploader ;
398
445
beforeEach ( ( ) => {
You can’t perform that action at this time.
0 commit comments