nagasurendra commited on
Commit
acb1b23
·
verified ·
1 Parent(s): be147cd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -5
app.py CHANGED
@@ -1,6 +1,7 @@
1
  import gradio as gr
2
  from simple_salesforce import Salesforce
3
  import os
 
4
  from dotenv import load_dotenv
5
 
6
  # Load environment variables from a .env file
@@ -17,14 +18,21 @@ sf = Salesforce(username=SF_USERNAME, password=SF_PASSWORD, security_token=SF_SE
17
  # Function to create a record in Salesforce with the uploaded file
18
  def create_vendor_scorecard(uploaded_file):
19
  try:
20
- # Upload the file to Salesforce
21
- # Convert the uploaded file into base64 format (Salesforce expects files in this format)
22
- file_data = uploaded_file.read()
23
- encoded_file = file_data.encode("base64")
 
 
 
24
 
25
  # Create a new record in the Vendor_Scorecard__c object with the file
26
  record = sf.Vendor_Scorecard__c.create({
27
- 'Uploaded_File__c': (uploaded_file.name, encoded_file) # This assumes the file is uploaded as a binary
 
 
 
 
28
  })
29
 
30
  return f"File uploaded successfully with ID: {record['id']}"
 
1
  import gradio as gr
2
  from simple_salesforce import Salesforce
3
  import os
4
+ import base64
5
  from dotenv import load_dotenv
6
 
7
  # Load environment variables from a .env file
 
18
  # Function to create a record in Salesforce with the uploaded file
19
  def create_vendor_scorecard(uploaded_file):
20
  try:
21
+ # Get the file path and read the file content
22
+ file_path = uploaded_file.name # This is the file path
23
+ with open(file_path, "rb") as file:
24
+ file_data = file.read()
25
+
26
+ # Encode the file content to base64
27
+ encoded_file = base64.b64encode(file_data).decode('utf-8')
28
 
29
  # Create a new record in the Vendor_Scorecard__c object with the file
30
  record = sf.Vendor_Scorecard__c.create({
31
+ 'Uploaded_File__c': {
32
+ 'filename': uploaded_file.name,
33
+ 'body': encoded_file,
34
+ 'contentType': uploaded_file.type
35
+ }
36
  })
37
 
38
  return f"File uploaded successfully with ID: {record['id']}"