Comhad a Uaslódáil mar Theimpléad
Treoirnósaíonn an treoir seo 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 d’fhoirmchlár do dhoiciméad i Legalesign.
An bhfuil tú ag iarraidh aiseolas beo faoi phróiseáil uaslódála? Féach ar Treoracha Tiontáin Uaslódála le Fáil le Liostálacha.
Cad a Mhúinfidh tú
Ag deireadh an treorach seo, beidh a fhios agat conas:
- Teimpléad nua a chruthú i do ghrúpa Legalesign
- ID an teimpléid agus URL uaslódála a fháil ó fhreagra an mhóitíf
- Do chomhad fhoinse a uaslódáil chuig an teimpléad
- Fíorú a dhéanamh ar rath uaslódála
Riachtanais
Sula dtosaíonn tú, déan cinnte go bhfuil:
- Cuntas Legalesign agat le rochtain API
- Do dintiúir fíordheimhnithe (féach ár treoir fíordheimhnithe)
- Comhad PDF, íomhá, nó Word ullmhaithe le hualach (maximim 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: Cruthaigh Teimpléad
Ar dtús, cruthaigh teimpléad folamh i Legalesign. Fillfaidh sé seo ar an ID teimpléid agus ar URL uaslódála sínithe réamhshocraithe don uaslódáil PDF. Chun é seo a dhéanamh beidh ort móitíf GraphQL a rith, má tá tú nua leis seo féach ar an Réamhrá do 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 iliomad faighteoirí
- É a athúsáid do shíntí éagsúla
Móitíf 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 bonn 64 do d’ghrúpa nó spás oibre (is féidir leat é seo a fháil ón URL i Console https://console.legalesign.com/)
- title: Ainm tuairisciúil do d’teimpléad (is féidir leat é seo a athrú níos déanaí)
Céim 2: Bain ID an Teimpléid agus URL Uaslódála
Fillfidh an móitíf ar an réad templateCreateOutput. Sábháil an réimse id agus an sreangán uploadUrl.
Freagra samplach:
{
"data": {
"createTemplate": {
"id": "dHBsYjQ5YTg5NWQtYWRhMy0xMWYwLWIxZGMtMDY5NzZlZmU0MzIx",
"uploadUrl": "https://s3.amazonaws.com/bucket/path?signature=..."
}
}
}
Is sreangán códáilte Base64 é ID an teimpléid. Sábháil an dá bhrí ó fhreagra an mhóitíf. Tá uploadUrl gearr-amach agus ba chóir é a úsáid go tapa.
Céim 3: Uaslódáil Do PDF
Úsáid an uploadUrl a fillíodh 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, úsáidimid 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 aon spleáchais breise ag teastáil — 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áiltear do PDF, déanann Legalesign go huathoibríoch:
- Scanadh do víris - Cinntíonn sé go bhfuil an comhad sábháilte
- Fíordheimhniú nó athrú comhaid - Seiceálann sé go bhfuil na PDFanna bailí, nó aistríonn sé comhaid thacaíochta cosúil le doiciméid Word agus íomhánna go PDF
- Easpórtáil eolas faoi leathanaigh - Faigheann sé comhaireamh agus toisí leathanaigh
- Próiseáil an chomhaid - Optamóidh sé é le haghaidh féachana agus sínithe
- Stóráil shlán - Glacann sé páirt i stóráil bhreise
Mairfidh an próiseas seo go ginearálta cúpla soicind. Nuair atá sé críochnaithe, beidh do theimpléad réidh le húsáid!
Ag Cuir Síniú agus Réimsí leis
Má tá tú ag iarraidh rannpháirtithe agus suíomhanna réimsí a uathoibriú, is féidir leat an comhad fhoinse a ullmhú sula n-uaslódáiltear ar bhealaí éagsúla:
- Clibeanna téacs - Cuir clibeanna téacs Legalesign isteach sa doiciméad foinse ionas gur féidir rannpháirtithe, réimsí sínithe agus réimsí foirme a chruthú go huathoibríoch le linn na próiseála. Féach an míniú API REST sa turas gasta agus tagairt an fhoirgnimh do Cuir clibeanna téacs i bhfeidhm.
- Réimsí PDF ceangailte go hinmheánach - Má tá réimsí foirme ceangailte cheana féin i do PDF, is féidir le Legalesign iad a úsáid mar chuid den phróiseas uaslódála agus ullmhúcháin teimpléid.
Céimeanna Eile
Anois go bhfuil teimpléad agat le PDF, is féidir leat:
- Cuir réimsí síniú leis - Úsáid an móitíf
createTemplateElementchun réimsí a chur leis - Cruthaigh róil - Sainaithin cé a shínfidh an doiciméad
- Seol le haghaidh sínithe - Úsáid an móitíf
sendchun a sheoladh chuig faighteoirí
Fadhbanna Coitianta agus Réitigh
Earráid "Gan cead"
Fíoraigh go bhfuil do ID grúpa ceart agus go bhfuil tú fíordheimhnithe leis an gcuntas ceart.
Earráid "Comhad ró-mhór"
Comhbhrúigh do PDF — is é an uasmhéid 50MB.
URL Uaslódála Éagtha
Úsáid an uploadUrl a fillíodh ó createTemplate go tapa. Má théann sé in éag roimh an uaslódáil, iarr URL nua leis an gceist upload ag úsáid an ID teimpléid a sábháil.
Earráid "PDF Neamhbhailí"
Oscail an PDF i léitheoir PDF chun a fhíorú go bhfuil sé bailí, ansin onnmhairigh nó sábháil arís é.
Rian Fíorama Uaslódála
Chun aiseolas beo a fháil ar phróiseáil uaslódála (scagadh, fíordheimhniú, críochnú), úsáid liostálacha. Féach ar Treoracha Tiontáin Uaslódála le Fáil le Liostálacha.