Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6aca5b2

Browse files
authored
Merge pull request #276 from aayusharyan/patch-2
Add functionality to change Raw Body Data before sending.
2 parents 6ecaee4 + 68e8461 commit 6aca5b2

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ function, it will be passed a FlowFile, a FlowChunk and isTest boolean (Default:
120120
* `prioritizeFirstAndLastChunk` Prioritize first and last chunks of all files. This can be handy if you can determine if a file is valid for your service from only the first or last chunk. For example, photo or video meta data is usually located in the first part of a file, making it easy to test support from only the first chunk. (Default: `false`)
121121
* `testChunks` Make a GET request to the server for each chunks to see if it already exists. If implemented on the server-side, this will allow for upload resumes even after a browser crash or even a computer restart. (Default: `true`)
122122
* `preprocess` Optional function to process each chunk before testing & sending. To the function it will be passed the chunk as parameter, and should call the `preprocessFinished` method on the chunk when finished. (Default: `null`)
123+
* `changeRawDataBeforeSend` Optional function to change Raw Data just before the XHR Request can be sent for each chunk. To the function, it will be passed the chunk and the data as a Parameter. Return the data which will be then sent to the XHR request without further modification. (Default: `null`). This is helpful when using FlowJS with [Google Cloud Storage](https://cloud.google.com/storage/docs/json_api/v1/how-tos/multipart-upload). Usage example can be seen [#276](https://github.com/flowjs/flow.js/pull/276). (For more, check issue [#170](https://github.com/flowjs/flow.js/issues/170)).
123124
* `initFileFn` Optional function to initialize the fileObject. To the function it will be passed a FlowFile and a FlowChunk arguments.
124125
* `readFileFn` Optional function wrapping reading operation from the original file. To the function it will be passed the FlowFile, the startByte and endByte, the fileType and the FlowChunk.
125126
* `generateUniqueIdentifier` Override the function that generates unique identifiers for each file. (Default: `null`)

src/flow.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@
8989
headers: {},
9090
withCredentials: false,
9191
preprocess: null,
92+
changeRawDataBeforeSend: null,
9293
method: 'multipart',
9394
testMethod: 'GET',
9495
uploadMethod: 'POST',
@@ -1376,6 +1377,10 @@
13761377

13771378
var uploadMethod = evalOpts(this.flowObj.opts.uploadMethod, this.fileObj, this);
13781379
var data = this.prepareXhrRequest(uploadMethod, false, this.flowObj.opts.method, this.bytes);
1380+
var changeRawDataBeforeSend = this.flowObj.opts.changeRawDataBeforeSend;
1381+
if (typeof changeRawDataBeforeSend === 'function') {
1382+
data = changeRawDataBeforeSend(this, data);
1383+
}
13791384
this.xhr.send(data);
13801385
},
13811386

0 commit comments

Comments
 (0)