I am uploading the file through the rest api to the parser storage but the file is corrupted during upload (ex: if original file size is 500kb then the uploaded file size is 0.23kb). Here is the code i am using.
Future<String?> uploadDocumentToCloud(
File? file, String? fileName, String? accessToken) async {
var url = Uri.parse(
"https://api.groupdocs.cloud/v1.0/parser/storage/file/$fileName");
var body = jsonEncode({
"file": file!.absolute.path,
});
var headers = {
"accept": "application/json",
"authorization": "Bearer $accessToken",
"Content-Type": "multipart/form-data",
"x-aspose-client": "Containerize.Swagger"
};
var response = await http.put(url, body: body, headers: headers);
if (response.statusCode == 200) {
var fName = jsonDecode(response.body)["uploaded"][0];
print("fileName : $fName");
return fName;
} else {
print("uploadFileError : ${response.body}");
print('reason : ${response.reasonPhrase}');
print(response.statusCode);
}
return null;
}
Future<String?> getParsedText(File? file, String? fileName) async {
var accessToken = await generateJwt();
var filePath = await uploadDocumentToCloud(file, fileName, accessToken);
var url = Uri.parse('https://api.groupdocs.cloud/v1.0/parser/text');
var body = jsonEncode({
"FileInfo": {
"FilePath": filePath,
}
});
var headers = {
'Content-Type': 'application/json',
'Accept': 'application/json',
'x-aspose-client': 'Containerize.Swagger',
'Authorization': 'Bearer $accessToken',
};
var response = await http.post(url, body: body, headers: headers);
if (response.statusCode == 200) {
var text = jsonDecode(response.body)["text"];
print("parsed Text : ${response.body}");
return text;
} else {
print(response.body);
print('reason : ${response.reasonPhrase}');
print(response.statusCode);
}
return null;
}