Uploads an image to the service and can be called with a POST Request to the following URL:
Additional parameters available are listed below.
A successful request will return a GUID corresponding to the uploaded file. This GUID can be used to queue up service requests, in addition to being used to query the status of your file.
//This sample uses the Request NodeJs library.
const request = require('request');
var servicesUrl = "https://azure.leadtools.com/api/";
var fileURL = 'https://demo.leadtools.com/images/pdf/leadtools.pdf';
var uploadUrl = servicesUrl + "UploadFile?fileurl=" + fileURL;
request.post(getRequestOptions(uploadUrl), uploadCallback);
function uploadCallback(error, response, body){
if(!error && response.statusCode == 200){
guid = body;
console.log("Unique ID returned by the Services: " + guid);
}else{
console.log("Failed to upload file with status code: " + response.statusCode);
}
}
function getRequestOptions(url){
//Function to generate and return HTTP request options.
var requestOptions ={
url: url,
headers: {
'Content-Length' : 0
},
auth: {
user:"Enter Application ID",
password:"Enter Application Password"
}
};
return requestOptions;
}
using System;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Threading;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using Newtonsoft.Json.Linq;
namespace Azure_Code_Snippets.DocumentationSnippets
{
class CloudServices_UploadFile_Demo
{
private string hostedServicesUrl = "https://azure.leadtools.com/api/";
public async void UploadImage()
{
string fileURL = "https://demo.leadtools.com/images/pdf/leadtools.pdf";
string uploadUrl = string.Format("UploadFile?fileurl={0}", fileURL);
var client = InitClient();
var result = await client.PostAsync(uploadUrl, null);
if (result.StatusCode == HttpStatusCode.OK)
{
//Unique ID returned by the services
string id = await result.Content.ReadAsStringAsync();
Console.WriteLine("Unique ID returned by the services: " + id);
}
else
Console.WriteLine("Request failed with the following response: " + result.StatusCode);
}
private HttpClient InitClient()
{
string AppId = "Enter Application ID";
string Password = "Enter Application Password";
HttpClient client = new HttpClient();
client.BaseAddress = new Uri(hostedServicesUrl);
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
string authData = string.Format("{0}:{1}", AppId, Password);
string authHeaderValue = Convert.ToBase64String(Encoding.UTF8.GetBytes(authData));
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", authHeaderValue);
return client;
}
}
}
#This sample uses the requests python library.
import requests, sys, time
servicesUrl = 'https://azure.leadtools.com/api/'
fileURL = 'https://demo.leadtools.com/images/pdf/leadtools.pdf'
#Your application ID.
appId = "Enter Application ID";
#Your application password.
password = "Enter Application Password";
baseUploadUrl='{}UploadFile?fileurl={}'
formattedUploadUrl = baseUploadUrl.format(servicesUrl, fileURL)
request = requests.post(formattedUploadUrl, auth=(appId, password))
if request.status_code != 200:
print("Error sending the conversion request")
print(request.text)
sys.exit()
#The File has been uploaded successfully. Now that we have the GUID, we can use it to queue up requests for the file
guid = request.text
print("Unique ID returned by the services: " + guid )
<?php
$servicesBaseUrl = "https://azure.leadtools.com/api/";
$fileURL = 'https://demo.leadtools.com/images/pdf/leadtools.pdf';
$uploadUrl = "%sUploadFile?fileurl=%s";
$uploadUrl = sprintf($uploadUrl, $servicesBaseUrl, $fileURL);
$requestOptions = GeneratePostOptions($uploadUrl);
$request = curl_init();
curl_setopt_array($request, $requestOptions);
if(!$guid = curl_exec($request)) //Make sure that the request was successful
{
if(curl_errno($request)){
echo "There was an error queueing the request \n\r";
echo curl_error($request);
curl_close($request);
return false;
}
}
curl_close($request);
//The request completed successfully. Now that we have the GUID, we can use it to queue up requests for the file.
echo "Unique ID returned by the services: $guid \n";
function GeneratePostOptions($url)
{
$appId = "Enter Application ID";
$password = "Enter Application Password";
$headers = array(
"Content-Length : 0"
);
$postOptions = array(
CURLOPT_POST => 1,
CURLOPT_URL => $url,
CURLOPT_FRESH_CONNECT => 1,
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_USERPWD => "$appId:$password",
CURLOPT_FORBID_REUSE => 1,
CURLOPT_HTTPHEADER => $headers
);
return $postOptions;
}
?>
use base 'HTTP::Message';
use LWP::UserAgent ();
my $servicesUrl = "https://azure.leadtools.com/api/";
my $fileURL = 'https://demo.leadtools.com/images/pdf/leadtools.pdf';
my $appId = 'Enter Application ID';
my $password = 'Enter Application Password';
my $headers = HTTP::Headers->new(
Content_Length => 0
);
$headers->authorization_basic($appId, $password);
#The User Agent to be used when making requests
my $ua = LWP::UserAgent->new;
my $uploadUrl = $servicesUrl . 'UploadFile?fileurl=' . $fileURL;
my $request = HTTP::Request->new(POST => $uploadUrl , $headers);
my $response = $ua->request($request);
if(!$response->is_success){
print STDERR $response->status_line, "\n";
exit;
}
my $guid = $response->decoded_content;
print("Unique ID returned by the services: " . $guid . "\n");