fileUpload static method
Build a function which handles file uploads.
handlerBuilder
is a function which will build the handler function. It will receive the
payload as a parameter.
Implementation
static String fileUpload({
required String Function(String payload) handlerBuilder,
required String Function(String payload) errorHandlerBuilder,
}) =>
function(
name: "uploadFile",
args: ["file"],
body: '''
const reader = new FileReader();
let base64 = "";
reader.onload = function (e) {
base64 = reader.result;
const fileObject = ${fileObject(fileNode: "file")}
${handlerBuilder("JSON.stringify(fileObject)")}
};
reader.onerror = function (error) {
${logDebugCall(message: '"Error while reading file: " + error')}
const fileObject = ${fileObject(fileNode: "file")}
const fileObjectAsString = JSON.stringify(fileObject);
${errorHandlerBuilder("JSON.stringify({'file': fileObjectAsString, 'error': 'An error occurred!'})")}
};
reader.readAsDataURL(file);
''',
);