Spaces:
Sleeping
Sleeping
Update app.py
Browse files94 unmodified lines959697989910010110210310410510610710810911011111211351 unmodified lines1651661671681691701 unmodified line1721731741751761771789 unmodified lines18818919019119219319494 unmodified linesreturn f"Error saving PDF: {str(e)}", None# Function to upload a file to Salesforce as ContentVersiondef upload_file_to_salesforce(file_path, filename, sf_connection):try:# Read file content and encode in base64with open(file_path, 'rb') as f:file_content = f.read()file_content_b64 = base64.b64encode(file_content).decode('utf-8')# Create ContentVersioncontent_version = sf_connection.ContentVersion.create({'Title': filename,'PathOnClient': filename,'VersionData': file_content_b64,'Description': f'Uploaded for Daily Progress Report'})# Get ContentDocumentId51 unmodified lines# Create Daily_Progress_Reports__c recordreport_description = "; ".join(captions)[:255] # Concatenate captions, limit to 255 charsdpr_record = sf.Daily_Progress_Reports__c.create({'Report_Description__c': report_description})dpr_record_id = dpr_record['id']1 unmodified line# Upload PDF to Salesforcepdf_content_document_id, pdf_upload_result = upload_file_to_salesforce(pdf_filepath, pdf_filename, sf)salesforce_result += pdf_upload_result + "\n"9 unmodified linesfor file in files:image_filename = os.path.basename(file.name)image_content_document_id, image_upload_result = upload_file_to_salesforce(file.name, image_filename, sf)if image_content_document_id:image_content_document_ids.append(image_content_document_id)94 unmodified lines959697989910010110210310410510610710810911011111211311411511651 unmodified lines1681691701711721731741 unmodified line1761771781791801811829 unmodified lines19219319419519619719894 unmodified linesreturn f"Error saving PDF: {str(e)}", None# Function to upload a file to Salesforce as ContentVersiondef upload_file_to_salesforce(file_path, filename, sf_connection, file_type):try:# Read file content and encode in base64with open(file_path, 'rb') as f:file_content = f.read()file_content_b64 = base64.b64encode(file_content).decode('utf-8')# Set description based on file typedescription = "Daily Progress Report PDF" if file_type == "pdf" else "Site Image"# Create ContentVersioncontent_version = sf_connection.ContentVersion.create({'Title': filename,'PathOnClient': filename,'VersionData': file_content_b64,'Description': description})# Get ContentDocumentId51 unmodified lines# Create Daily_Progress_Reports__c recordreport_description = "; ".join(captions)[:255] # Concatenate captions, limit to 255 charsdpr_record = sf.Daily_Progress_Reports__c.create({'Report_Description__c': report_description})dpr_record_id = dpr_record['id']1 unmodified line# Upload PDF to Salesforcepdf_content_document_id, pdf_upload_result = upload_file_to_salesforce(pdf_filepath, pdf_filename, sf, "pdf")salesforce_result += pdf_upload_result + "\n"9 unmodified linesfor file in files:image_filename = os.path.basename(file.name)image_content_document_id, image_upload_result = upload_file_to_salesforce(file.name, image_filename, sf, "image")if image_content_document_id:image_content_document_ids.append(image_content_document_id)
app.py+8-4