Reputation: 1
I need to create an issue with attachement in MantisBT via REST API like it's written here : https://documenter.getpostman.com/view/29959/mantis-bug-tracker-rest-api/7Lt6zkP?version=latest#2d3878c7-4195-42f7-53b7-9cc11f7501f4
How can i transform a local text file content into a blob string ?
I'm running on Linux CentOS 7 and need to do it locally without using any browser or human interaction, just fully automated.
I made a little Python script that store the file content in a json attribute but i need to have the BLOB representation of this content.
import json
reportpath = '/var/lib/jenkins/jobs/SimplePipeline/workspace/reports/CompilationReport.txt'
compilReportFile = open(reportpath, 'r')
compilContent = compilReportFile.read()
compilReportFile.close()
with open('/home/Jenkins/PFE/Static/newMantisRequestBody.json', 'r') as file:
json_data = json.load(file)
json_data["description"] = compilContent
with open('/home/Jenkins/PFE/Static/newMantisRequestBody.json', 'w') as file:
json.dump(json_data, file, indent=2)
I expect to end with something like this :
"files": [
{
"name": "test.txt",
"content": "VGhpcyBpcyBhIFRFU1QuDQpUaGlzIGlzIGEgVEVTVC4NClRoaXMgaXMgYSBURVNULg0KVGhpcyBpcyBhIFRFU1QuDQpUaGlzIGlzIGEgVEVTVC4="
}
]
Or, now i'm only able to do this :
"description": "MY FILE CONTENT STRING HERE"
Do you guys have an idea ?
Thanks !
Upvotes: 0
Views: 1376
Reputation: 1
Actually, i needed to transform my file content into a Base64 String before inserting it in my Json.
See the TMS's comment above if you want more precisions.
Thank you again !
Upvotes: 0