Comhad a Uaslódáil mar Theimpléad
Treoir seo a thugann tú tríd an bpróiseas iomlán chun teimpléad a chruthú agus PDF, íomhá, nó comhad Word a uaslódáil le húsáid mar do theimpléad doiciméad i Legalesign.
Cad a D'fhoghlaimeoidh tú
Ag deireadh an treorach seo, beidh a fhios agat conas:
- Teimpléad nua a chruthú i do ghrúpa Legalesign
- Aithint teimpléid agus URL uaslódála a fháil ón bhfreagra mutation
- Do chomhad fhoinse a uaslódáil chuig an teimpléad
- Fíorú a dhéanamh go raibh an uaslódáil rathúil
Riachtanais Réamhbhunaithe
Sula dtosaíonn tú, cinntigh go bhfuil agat:
- Cuntas Legalesign le rochtain API
- Do chuid cr credentialsúnais fhíordheimhnithe (féach an treoir fíordheimhnithe)
- PDF, íomhá, nó comhad Word réidh le uaslódáil (uasmhéid 50MB)
- Do ID grúpa (an spás oibre ina dteastaíonn uait an teimpléad a chruthú)
An Próiseas Iomlán
Céim 1: Teimpléad a Chruthú
Ar dtús, cruthaigh teimpléad folamh i Legalesign. Filleann sé an dá ID teimpléid agus URL uaslódála ré-síniú do uaslódáil PDF. Chun é sin a dhéanamh beidh ort mutation GraphQL a reáchtáil, má tá sé seo nua duit féach ar an Réamhrá chuig GraphQL.
Cad is Teimpléad ann?
Is struchtúr doiciméid in-athúsáidte é teimpléad i Legalesign. Nuair a uaslódálann tú PDF chuig teimpléad, is féidir leat:
- Réimsí sínithe agus réimsí foirme a chur leis
- É a sheoladh chuig roinnt faighteoirí
- É a athúsáid le sínitheoirí éagsúla
Mutation GraphQL
mutation CreateTemplate($input: templateCreateInput!) {
createTemplate(input: $input) {
id
uploadUrl
}
}
Athróga Ionchuir
{
"input": {
"groupId": "grpYourGroupAPIId",
"title": "Employment Contract Template"
}
}
Míniú ar Pharaiméadair
- groupId: ID bunaithe ar Base64 do do ghrúpa/spás oibre (is féidir leat é seo a fháil ón URL sa Console https://console.legalesign.com/)
- title: Ainm tuairisciúil do do theimpléad (is féidir leat é a athrú níos déanaí)
Céim 2: An Aithint Teimpléid agus URL Uaslódála a Aisghabháil
Tugann an mutation objacht templateCreateOutput. Sábháil an réimse id agus an slán téacs uploadUrl.
Freagra samplach:
{
"data": {
"createTemplate": {
"id": "dHBsYjQ5YTg5NWQtYWRhMy0xMWYwLWIxZGMtMDY5NzZlZmU0MzIx",
"uploadUrl": "https://s3.amazonaws.com/bucket/path?signature=..."
}
}
}
Is sreang códaithe Base64 é an ID teimpléid. Sábháil an dá luach ón bhfreagra. Tá an uploadUrl gearrshaol agus ba chóir é a úsáid láithreach.
Céim 3: Do PDF a Uaslódáil
Úsáid an uploadUrl a fuarthas chun do chomhad PDF a uaslódáil go díreach chuig S3. Beidh sé seo éagsúil ag brath ar do stac forbartha. Sa sampla javascript atá againn, d’úsáid muid fetch ach is féidir leat leabharlanna eile a úsáid lena n-áirítear aws-amplify.
Samplaí Oibre Iomlána
- JavaScript
- Python
- C#
import fs from 'fs';
const AUTH_TOKEN = '<token-from-authentication-guide>';
const uploadPdfTemplate = async (groupId, title, pdfFilePath) => {
const graphqlEndpoint = 'https://graphql.uk.legalesign.com/graphql';
// Step 1: Create the template
console.log('Creating template...');
const createResponse = await fetch(graphqlEndpoint, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${AUTH_TOKEN}`
},
body: JSON.stringify({
query: `
mutation CreateTemplate($input: templateCreateInput!) {
createTemplate(input: $input) {
id
uploadUrl
}
}
`,
variables: {
input: {
groupId: groupId,
title: title
}
}
})
});
const createResult = await createResponse.json();
const templateId = createResult.data.createTemplate.id;
const uploadUrl = createResult.data.createTemplate.uploadUrl;
console.log('Template created with ID:', templateId);
// Step 2: Upload the PDF
console.log('Uploading PDF...');
const fileData = fs.readFileSync(pdfFilePath);
const uploadResponse = await fetch(uploadUrl, {
method: 'PUT',
body: fileData,
headers: {
'Content-Type': 'application/pdf'
}
});
if (!uploadResponse.ok) {
throw new Error(`Upload failed: ${uploadResponse.statusText}`);
}
console.log('PDF uploaded successfully!');
return {
success: true,
templateId: templateId,
title: title
};
};
// Usage example
uploadPdfTemplate(
'grpYourGroupId',
'Employment Contract',
'./contract.pdf'
).then(result => {
console.log('Complete!', result);
}).catch(error => {
console.error('Error:', error);
});
Níl gá le spleáchais bhreise — cuimsíonn Node.js 18+ fetch go dúchasach.
import requests
from gql import gql, Client
from gql.transport.requests import RequestsHTTPTransport
def upload_pdf_template(graphql_endpoint, auth_token, group_id, title, pdf_file_path):
transport = RequestsHTTPTransport(
url=graphql_endpoint,
headers={'Authorization': auth_token}
)
client = Client(transport=transport, fetch_schema_from_transport=True)
# Step 1: Create the template
print('Creating template...')
create_mutation = gql('''
mutation CreateTemplate($input: templateCreateInput!) {
createTemplate(input: $input) {
id
uploadUrl
}
}
''')
create_result = client.execute(
create_mutation,
variable_values={
'input': {
'groupId': group_id,
'title': title
}
}
)
template_id = create_result['createTemplate']['id']
upload_url = create_result['createTemplate']['uploadUrl']
print(f'Template created with ID: {template_id}')
# Step 2: Upload the PDF
print('Uploading PDF...')
with open(pdf_file_path, 'rb') as f:
file_data = f.read()
response = requests.put(
upload_url,
data=file_data,
headers={'Content-Type': 'application/pdf'}
)
if response.status_code != 200:
raise Exception(f'Upload failed: {response.status_code}')
print('PDF uploaded successfully!')
return {
'success': True,
'templateId': template_id,
'title': title
}
if __name__ == '__main__':
result = upload_pdf_template(
'https://graphql.uk.legalesign.com/graphql',
'Bearer YOUR_TOKEN',
'grpYourGroupId',
'Employment Contract',
'./contract.pdf'
)
print('Complete!', result)
using System;
using System.IO;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using GraphQL;
using GraphQL.Client.Http;
using GraphQL.Client.Serializer.Newtonsoft;
using Newtonsoft.Json.Linq;
public class PdfTemplateUploader
{
private readonly GraphQLHttpClient graphQLClient;
public PdfTemplateUploader(string graphqlEndpoint, string authToken)
{
graphQLClient = new GraphQLHttpClient(graphqlEndpoint, new NewtonsoftJsonSerializer());
graphQLClient.HttpClient.DefaultRequestHeaders.Add("Authorization", authToken);
}
public async Task<UploadResult> UploadPdfTemplate(
string groupId,
string title,
string pdfFilePath)
{
// Step 1: Create the template
Console.WriteLine("Creating template...");
var createMutation = new GraphQLRequest
{
Query = @"
mutation CreateTemplate($input: templateCreateInput!) {
createTemplate(input: $input) {
id
uploadUrl
}
}
",
Variables = new
{
input = new
{
groupId = groupId,
title = title
}
}
};
var createResponse = await graphQLClient.SendMutationAsync<dynamic>(createMutation);
string templateId = createResponse.Data.createTemplate.id;
string uploadUrl = createResponse.Data.createTemplate.uploadUrl;
Console.WriteLine($"Template created with ID: {templateId}");
// Step 2: Upload the PDF
Console.WriteLine("Uploading PDF...");
using var httpClient = new HttpClient();
var fileBytes = await File.ReadAllBytesAsync(pdfFilePath);
var content = new ByteArrayContent(fileBytes);
content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/pdf");
var putResponse = await httpClient.PutAsync(uploadUrl, content);
if (!putResponse.IsSuccessStatusCode)
{
throw new Exception($"Upload failed: {putResponse.StatusCode}");
}
Console.WriteLine("PDF uploaded successfully!");
return new UploadResult
{
Success = true,
TemplateId = templateId,
Title = title
};
}
}
public class UploadResult
{
public bool Success { get; set; }
public string TemplateId { get; set; }
public string Title { get; set; }
}
class Program
{
static async Task Main(string[] args)
{
var uploader = new PdfTemplateUploader(
"https://graphql.uk.legalesign.com/graphql",
"Bearer YOUR_TOKEN"
);
var result = await uploader.UploadPdfTemplate(
"grpYourGroupId",
"Employment Contract",
"./contract.pdf"
);
Console.WriteLine($"Complete! Template ID: {result.TemplateId}");
}
}
Cad a Tharlaíonn Tar éis Uaslódáil?
Nuair a uaslódáladh do PDF, déanann Legalesign go huathoibríoch:
- Scansáil ar víris - Cinntíonn sé go bhfuil an comhad sábháilte
- Bailíochtú nó tiontú an chomhaid - Seiceálann sé go bhfuil PDFanna bailí, nó tiontaíonn sé comhaid tacaithe mar dhoiciméid Word agus íomhánna go PDF
- Eolas leathanach a bhaint - Faigheann sé comhaireamh leathanaigh agus toisí
- An comhad a phróiseáil - Optamóidh sé é le haghaidh féachaint agus sínithe
- Stóráil go sábháilte - Bogann sé é go stóráil bhuan
Is minic a thógann an próiseas seo cúpla soicind. Nuair atá sé críochnaithe, tá do theimpléad réidh le húsáid!
Dul Chun Cinn Uaslódála a Rianú
Chun aiseolas fíor-ama a fháil ar phróiseáil uaslódála (scagadh, bailíochtú, críochnú), úsáid síntiúis. Féach Rian Uaslódála le Síntiúis.
Mar mhalairt air sin, déan polláil ar an réimse fileUploaded den teimpléad go dtí go bhfilleann sé true:
query CheckUploadStatus($id: ID!) {
template(id: $id) {
id
fileUploaded
}
}
Dáileadh Sínithe agus Réimsí
Má tá tú ag iarraidh rannpháirtithe agus suíochán réimsí a uathoibriú, is féidir leat an comhad fhoinse a ullmhú roimh uaslódáil i mbealach nó dhó éagsúla:
- Clibeanna téacs - Cuir clibeanna téacs Legalesign isteach sa doiciméad foinse ionas go mbeidh rannpháirtithe, réimsí sínithe, agus réimsí foirme á gcruthú go huathoibríoch le linn an phróisis. Féach ar mhíniú REST API sa túir éigeantach agus tagairt don Comhéadan Convert text tags.
- Réimsí PDF fite fuaite - Má tá réimsí foirme fite fuaite cheana féin i do PDF, is féidir le Legalesign iad a úsáid mar chuid den uaslódáil agus den phróiseas ullmhúcháin teimpléid.
Céimeanna Eile
Anois go bhfuil teimpléad agat le PDF, is féidir leat:
- Réimsí sínithe a chur leis - Úsáid an mutation
createTemplateElementchun réimsí a chur leis - Róil a chruthú - Sainmhínigh cé a shínefaidh an doiciméad
- Seol chuig sínitheoirí - Úsáid an mutation
sendchun é a sheoladh chuig faighteoirí
Fadhbanna Coitianta agus Réitigh
Earráid "Gan cead"
Déan fíorú go bhfuil do ID grúpa ceart agus go bhfuil tú sínithe isteach leis an gcuntas ceart.
Earráid "Comhad ró-mhór"
Comhthéigh do PDF — is é an uasmhéid 50MB.
D'éag URL Uaslódála
Úsáid an uploadUrl a thug an createTemplate go pras. Má éagaíonn sé sular uaslódáil tú, iarr URL nua leis an gceist upload ag baint úsáide as an ID teimpléid sábháilte.
Earráid "PDF Neamhbhailí"
Oscail an PDF i léitheoir PDF chun a fhíorú go bhfuil sé bailí, ansin easpórtáil nó sábháil arís é.