Scroll to top

Secure Gateway StorageBox API: Secure File Upload Environments for Enterprises

Secure Gateway StorageBox offers a global solution for safe and seamless file uploads in a fully isolated environment, ensuring no uploaded file is executed. Whether hosted on-premises or in the cloud, it provides adaptability with the trusted ALSCO domain or the flexibility of your custom domain. Harness the unmatched protection and data integrity of our API, designed to integrate effortlessly with any system.

Note: Always ensure your API token and credentials are kept secure. Do not expose sensitive data in client-side code.

Start using an API

The Secure Gateway Storage Box API simplifies complex tasks, making it as easy as a single cURL command for developers of all skill levels
curl --location --request POST "https://api1.nodesbox.com/index.php?linkurl=external&token=frdecsxE24r35ty453&domain=nodesbox.com" --form "file_from_alsco=@timeout.jpg"

Code Breakdown (cURL):

curl: Command-line tool used for making HTTP requests.

--location: Allows `curl` to follow any redirects.

--request POST: Specifies a POST request, commonly used to send data to be processed.

--URL: The API endpoint to which the request is being sent, including authentication or access token and domain specifications.

linkurl: Developers can choose between two options:

--form: Indicates that the data being sent is form data.

file_from_alsco=@timeout.jpg: Uploads the "timeout.jpg" file using the "file_from_alsco" parameter.

Expected Response (cURL):

https://storage.nodesbox.com/nodesbox.com/2024/08/31/2024_08_31_12076004052_4302079099158962.png


1- PHP Example

<?php
 
 header("Content-Type: text/plain");
 
 $Domain= "nodesbox.com";
 $Token = "frdecsxE24r35ty453";
 $File_Path = "1.gif";
 
 $URL = "https://api1.nodesbox.com/index.php?linkurl=external&token=" . urlencode($Token) . "&domain=" . urlencode($Domain);
 
 $ch = curl_init();
 
 curl_setopt($ch, CURLOPT_URL, $URL);
  curl_setopt($ch, CURLOPT_POST, 1);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  curl_setopt($ch, CURLOPT_POSTFIELDS, ['file_from_alsco' => new CURLFile($File_Path)]);
  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
 
 $response = curl_exec($ch);
 
 if (curl_errno($ch))
 {
  // echo 'cURL Error:' . curl_error($ch);
 }
 
 $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  // echo 'HTTP Status Code: ' . $http_code;
 
 curl_close($ch);
 
 echo $response;
 
?>

Code Breakdown (PHP):

header(): Sets the response type to plain text.

curl_init(): Initializes a cURL session.

curl_setopt(): Sets various options for the cURL session.

CURLFile: Represents a file to be uploaded.

curl_exec(): Executes the cURL session and gets the response.

curl_errno(): Checks if there were any errors during the cURL session.

curl_getinfo(): Retrieves information about the cURL session, like the HTTP status code in this case.

curl_close(): Closes the cURL session.

Note: If you are using WHM, be sure to install php74-php-curl from the PHP extensions in EasyApache 4.

Expected Response (PHP):

https://storage.nodesbox.com/nodesbox.com/2024/08/31/2024_08_31_12076004052_4302079099158962.png



2- HTML Example

<html>
<head>

 <meta charset="UTF-8">
 <meta name="viewport" content="width=device-width, initial-scale=1.0">
 <title>File Upload Form</title>
</head>
<body>

 <form id="uploadForm" action="https://api1.nodesbox.com/index.php?linkurl=external&token=frdecsxE24r35ty453&domain=nodesbox.com" method="post" enctype="multipart/form-data" onsubmit="SecureGatewaySubmitForm(event)">
  <label for="fileToUpload">Select file to upload:</label>
  <input type="file" name="file_from_alsco" id="fileToUpload">
  <input type="submit" value="Upload File" name="submit">
 </form>

 <div id="responseOutput"></div>
 <script src="https://alscotoday.com/blog/Secure_Gateway_StorageBox/sg_script.js"></script>

</body>
</html>

Code Breakdown (HTML):

<html>: Defines the HTML document with the "en" (English) language.

<head>: Contains metadata and links to external resources.

<meta charset="UTF-8">: Specifies the character encoding as UTF-8.

<meta name="viewport" content="width=device-width, initial-scale=1.0">: Sets the viewport properties for responsive design.

<title>: Sets the title of the web page.

<body>: Contains the visible content of the web page.

<form>: Defines a form for file upload.

<label for="fileToUpload">: Labels the file input field.

<input type="file" name="file_from_alsco" id="fileToUpload">: Allows users to select a file for upload.

<input type="submit" value="Upload File" name="submit">: Provides a button to submit the form.

<div id="responseOutput"></div> This div will display the server response

<script></script> This script is repsonse to print server response  

</body>: Closes the HTML Body.

</body>: Closes the HTML document.

Expected Response (HTML):

https://storage.nodesbox.com/nodesbox.com/2024/08/31/2024_08_31_12076004052_4302079099158962.png



3- ASP.NET Example

To achieve the same functionality in an ASP.NET application, you would typically use the HttpClient class, which is available in the .NET framework. The HttpClient class is designed for sending HTTP requests and receiving HTTP responses from a resource identified by a URI.

Below is an ASP.NET example that accomplishes this:

Setting up the Project:

. Create a new ASP.NET Core Web Application.
. Choose an "Empty" template.
. Install the necessary NuGet package:

Install-Package System.Net.Http

Writing the Code:


 using System;
 using System.Net.Http;
 using System.Threading.Tasks;
 using Microsoft.AspNetCore.Mvc;
 
 namespace AspNetCoreHttpClientExample.Controllers
 {
  [Route("api/[controller]")]
  [ApiController]
  public class UploadController : ControllerBase
  {
   private readonly IHttpClientFactory _httpClientFactory;
  
   public UploadController(IHttpClientFactory httpClientFactory)
   {
    _httpClientFactory = httpClientFactory;
   }
  
   [HttpPost("upload")]
   public async Task UploadFile()
   {
    var requestUri = "https://api1.nodesbox.com/index.php?linkurl=external&token=frdecsxE24r35ty453&domain=nodesbox.com";
    
    // Simulating a file upload. Make sure to replace 'filePath' with the actual path to your file.
    var filePath = "path_to_your_file/timeout.jpg";
    using var stream = System.IO.File.OpenRead(filePath);
    using var content = new MultipartFormDataContent
    {
     { new StreamContent(stream), "file_from_alsco", "timeout.jpg" }
    };
    
    var client = _httpClientFactory.CreateClient();
    var response = await client.PostAsync(requestUri, content);
    
    if (response.IsSuccessStatusCode)
    {
     // Handle the response (e.g., parse JSON, return the result to the caller, etc.)
     return Ok(await response.Content.ReadAsStringAsync());
    }
    else
    {
     return BadRequest("Error uploading file.");
    }
   }
  }
 }

Code Breakdown (ASP.NET):

A. Explanation:

We've set up a simple API endpoint in an ASP.NET Core application.

The [HttpPost("upload")] attribute specifies that this method should be invoked with a POST request to the "/upload" endpoint.

We're using IHttpClientFactory to retrieve an instance of HttpClient. This is the recommended approach for using HttpClient in ASP.NET Core applications, as it manages the lifecycle of the underlying handler and ensures that sockets are reused efficiently.

We're creating a MultipartFormDataContent to hold the file data. In this example, it's assumed that the file "timeout.jpg" is being read from the local filesystem and attached to the request.

The PostAsync method is used to send the POST request with the file attached.

Finally, we check if the response indicates success (IsSuccessStatusCode) and return the response content accordingly.

B. Configuration:

Ensure that you've registered the HttpClient service in the Startup.cs:


public void ConfigureServices(IServiceCollection services)
{
services.AddHttpClient();
// ... other services
}



With this configuration, initiate the file upload by sending a POST request to the /api/upload/upload endpoint in your ASP.NET application.

Expected Response (ASP.NET):

https://storage.nodesbox.com/nodesbox.com/2024/08/31/2024_08_31_12076004052_4302079099158962.png



This URL is the direct link to the uploaded file. Once you receive this URL, it can be effortlessly integrated into your software or application. You can use it to access, share, or store the file as per your requirements.

For a hands-on demonstration of the API's functionality, check out our example page: example.html.

For additional details and advanced API features, please visit alscotoday.com.