uploadViaHTTP method
Future<RequestResponse<FrappeUploadFileResponse?> >
uploadViaHTTP(
- FrappeUploadFileParams uploadFileParams
override
Returns FrappeUploadFileResponse on uploading of file. This method should be used if uploadFile fails.
Handles files of type File if native and Uint8List if from the web.
Implementation
@override
Future<RequestResponse<FrappeUploadFileResponse?>> uploadViaHTTP(
FrappeUploadFileParams uploadFileParams) async {
await getFrappe().checkAppInstalled(features: ['uploadViaHTTP']);
validateUploadFileArgs(uploadFileParams);
uploadFileParams.fileData =
base64Encode(getByteList(uploadFileParams.file));
uploadFileParams.fileSize = getFileSize(uploadFileParams.file);
uploadFileParams.cmd = getFrappe().getAppsVersion('renovation_core') != null
? 'renovation_core.handler.uploadfile'
: 'frappe.handler.uploadfile';
final response = await Request.initiateRequest(
url: config.hostUrl,
method: HttpMethod.POST,
contentType: ContentTypeLiterals.APPLICATION_X_WWW_FORM_URLENCODED,
data: uploadFileParams.toJson());
if (response.isSuccess) {
final dynamic responseObj = response.data!.message;
if (responseObj != null) {
final uploadFileResponse = FrappeUploadFileResponse()
.fromJson<FrappeUploadFileResponse>(responseObj);
return RequestResponse.success(uploadFileResponse,
rawResponse: response.rawResponse);
} else {
return RequestResponse.fail(handleError(
'uploadViaHttp',
response.error ??
ErrorDetail(
info: Information(rawResponse: response.rawResponse))));
}
} else {
return RequestResponse.fail(handleError('uploadViaHttp', response.error));
}
}