Pull serialized file data from task data, send to s3 (#10)
This commit is contained in:
parent
4186b875b4
commit
7429a0725f
4
app.py
4
app.py
|
@ -116,7 +116,7 @@ def auth_callback(plugin_display_name, auth_name):
|
|||
return redirect(f"{redirect_url}?response={response}")
|
||||
|
||||
|
||||
@app.route("/v1/do/<plugin_display_name>/<command_name>")
|
||||
@app.route("/v1/do/<plugin_display_name>/<command_name>", methods = ["GET", "POST"])
|
||||
def do_command(plugin_display_name, command_name):
|
||||
command = PluginService.command_named(plugin_display_name, command_name)
|
||||
if command is None:
|
||||
|
@ -124,7 +124,7 @@ def do_command(plugin_display_name, command_name):
|
|||
f"Command not found: {plugin_display_name}:{command_name}", status=404
|
||||
)
|
||||
|
||||
params = request.args.to_dict()
|
||||
params = request.values.to_dict()
|
||||
raw_task_data = params.pop('spiff__task_data', '{}')
|
||||
task_data = json.loads(raw_task_data)
|
||||
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
"""UploadFile."""
|
||||
import base64
|
||||
|
||||
from botocore.exceptions import ClientError # type: ignore
|
||||
from connector_aws.auths.simpleAuth import SimpleAuth # type: ignore
|
||||
|
||||
|
@ -8,7 +10,7 @@ class UploadFileData:
|
|||
|
||||
def __init__(
|
||||
self,
|
||||
file_data: bytes,
|
||||
file_data: str,
|
||||
bucket: str,
|
||||
object_name: str,
|
||||
):
|
||||
|
@ -25,11 +27,14 @@ class UploadFileData:
|
|||
|
||||
def execute(self, config, task_data):
|
||||
"""Execute."""
|
||||
|
||||
file_data = self.parse_file_data(self.file_data)
|
||||
|
||||
# Upload the file
|
||||
client = SimpleAuth("s3", config).get_resource()
|
||||
try:
|
||||
result = client.Object(self.bucket, self.object_name).put(
|
||||
Body=self.file_data
|
||||
Body=file_data
|
||||
)
|
||||
status = str(result["ResponseMetadata"]["HTTPStatusCode"])
|
||||
|
||||
|
@ -43,3 +48,12 @@ class UploadFileData:
|
|||
status = "500"
|
||||
|
||||
return {"response": response, "status": status, "mimetype": "application/json"}
|
||||
|
||||
def parse_file_data(self, raw_data):
|
||||
# looks like:
|
||||
# "data:application/pdf;name=Harmeet_13435%20(1).pdf;base64,JVBERi0xLjQKJZOMi54gUmVwb3J0TGFiIEdlb....="
|
||||
parts = raw_data.split(";", 2)
|
||||
base64_data = parts[2].removeprefix("base64,")
|
||||
file_data = base64.b64decode(base64_data)
|
||||
|
||||
return file_data
|
||||
|
|
Loading…
Reference in New Issue