Add functionality to change Raw Body Data before sending. by aayusharyan · Pull Request #276 · flowjs/flow.js (original) (raw)
@AidasK
Hey,
Thanks for the quick response.
There is specification in the body for GCS, (check here). So, the code can be used to customize like this. 👇
var preprocessChunk = function(flowChunk, data) {
var e = data.get('file');
var chunk_data = flowChunk.bytes;
var chunkNumber = flowChunk.offset;
var objectNameInfo = {
'name': 'file'+chunkNumber+'_.jpg',
'metadata': {
'chunkNumber': chunkNumber
}
};
var jsonse = JSON.stringify(objectNameInfo);
var fileMetaBlob = new Blob([jsonse], {type: 'application/json'});
var blob = new Blob([
"--foo_bar_baz\n",
"Content-Type: "+fileMetaBlob.type+"; charset=UTF-8\n",
"\n",
fileMetaBlob,
"\n",
"--foo_bar_baz\n",
"Content-Type: "+chunk_data.type+"\n",
"\n",
chunk_data,
"\n",
"--foo_bar_baz--",
], {type: "text/plain"});
return blob;
}
However, I am not sure what to include in the documentation. I mean, there is no example for other functionalities of the library. So, maybe keep it uniform and include explanation only without example... 🤷♂