Upload File API(Upload Local or Remote File)

You use the Upload File API to upload remote file or local file:

Upload Remote File

  1. Create a request and upload a file:
    #!/bin/bash
    curl -F AddRemoteFile={REMOTE_FILE_URL} 'https://fax.to/api/v2/files?api_key=API_KEY'
    
    <?php
    
    $targetUrl       = 'https://fax.to/api/v2/files?api_key=API_KEY';
    
    //for local file upload
    if (function_exists('curl_file_create'))  // php 5.5+
          $cFile     = curl_file_create('LOCAL_FILE_PATH');
    else 
          $cFile     = '@' . realpath('LOCAL_FILE_PATH');
    
    $post            = array('AddRemoteFile' => 'REMOTE_FILE_URL'); 
    $ch              = curl_init();
    curl_setopt($ch, CURLOPT_URL,$targetUrl);
    curl_setopt($ch, CURLOPT_POST,1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
    $response        = curl_exec($ch);
    
    // Decode the json object you retrieved when you ran the request.
    $decodedResponse = json_decode($response, true);
    var_dump($decodedResponse);
    
    
    import urllib
    
    url         = {'api_key': 'API_KEY'}
    data        = {'file': 'REMOTE_FILE_URL'}
    
    url_params  = 'https://fax.to/api/v2/files?' + urllib.urlencode(url)
    data_params = urllib.urlencode(data);
    response    = urllib.urlopen(url_params,data_params)
    print response.read()
    
    require "net/http"
    require "uri"
    
    params       = {'file' => 'REMOTE_FILE_URL'}
    json_headers = {"Content-Type" => "application/json"}
    
    uri          = URI.parse("https://fax.to/api/v2/files?api_key=API_KEY")
    http         = Net::HTTP.new(uri.host, uri.port)
    response     = http.post(uri.path, params.to_json, json_headers)
    
    puts response
    
    {
      "status": "success",
      "document_id": 11,
      "document": {
      "filename": "598317a8404bd.pdf.tiff",
      "filename_uploaded": "verify.txt",
      "orig_filename": "598317a8404bd.pdf",
      "file_extension": "txt",
      "total_pages": 1,
      "filesize": 3650,
      "preview_in_storage": 1,
      "preview_file": "598317a8404bd.pdf.preview.jpg",
      "preview_image": null,
      "s3": null,
      "user_id": 2,
      "updated_at": "2017-08-03 12:31:38",
      "created_at": "2017-08-03 12:31:38",
      "id": 300,
      }
    }
    

Upload Local File

  1. Create a request and upload a file:
    #!/bin/bash
    curl  -F file=@{LOCAL_FILE_PATH} 'https://fax.to/api/v2/files?api_key=API_KEY'
    
    <?php
    
    $targetUrl       = 'https://fax.to/api/v2/files?api_key=API_KEY';
    
    //for local file upload
    if (function_exists('curl_file_create'))  // php 5.5+
          $cFile     = curl_file_create('LOCAL_FILE_PATH');
    else 
          $cFile     = '@' . realpath('LOCAL_FILE_PATH');
    
    $post            = array('file'=> $cFile); 
    $ch              = curl_init();
    curl_setopt($ch, CURLOPT_URL,$targetUrl);
    curl_setopt($ch, CURLOPT_POST,1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
    $response        = curl_exec($ch);
    
    // Decode the json object you retrieved when you ran the request.
    $decodedResponse = json_decode($response, true);
    var_dump($decodedResponse);
    
    
    import urllib
    
    url         = {'api_key': 'API_KEY'}
    data        = {'file': 'LOCAL_FILE_PATH'}
    
    url_params  = 'https://fax.to/api/v2/files?' + urllib.urlencode(url)
    data_params = urllib.urlencode(data);
    response    = urllib.urlopen(url_params,data_params)
    print response.read()
    
    require "net/http"
    require "uri"
    
    params       = {'file' => 'LOCAL_FILE_PATH'}
    json_headers = {"Content-Type" => "application/json"}
    
    uri          = URI.parse("https://fax.to/api/v2/files?api_key=API_KEY")
    http         = Net::HTTP.new(uri.host, uri.port)
    response     = http.post(uri.path, params.to_json, json_headers)
    
    puts response
    
    {
      "status": "success",
      "document_id": 11,
      "document": {
      "filename": "598317a8404bd.pdf.tiff",
      "filename_uploaded": "verify.txt",
      "orig_filename": "598317a8404bd.pdf",
      "file_extension": "txt",
      "total_pages": 1,
      "filesize": 3650,
      "preview_in_storage": 1,
      "preview_file": "598317a8404bd.pdf.preview.jpg",
      "preview_image": null,
      "s3": null,
      "user_id": 2,
      "updated_at": "2017-08-03 12:31:38",
      "created_at": "2017-08-03 12:31:38",
      "id": 300,
      }
    }