(504) Reason: Gateway Time-out

upload_request = UploadFileRequest(map_files, file_name, storage_name) is giving the error

(504)
Reason: Gateway Time-out
HTTP response headers: HTTPHeaderDict({‘cache-control’: ‘no-cache’, ‘content-type’: ‘text/html’})
HTTP response body:

504 Gateway Time-out


The server didn’t respond in time.

@abhijittaneja

Why you are getting a 504 Gateway Timeout

UploadFileRequest(map_files, file_name, storage_name) sends the whole file to the Aspose Cloud gateway in a single HTTP request.
If the request does not finish within the timeout that the SDK’s HTTP client is configured with, the gateway aborts the call and returns 504.

Typical causes

Cause What happens Quick fix
Large file (tens of MB or more) The single request needs more time than the default timeout (≈ 100 s). Increase the client timeout or upload the file in smaller chunks.
Default client timeout is too short The SDK aborts the request before the server finishes receiving the data. Set a larger Timeout value in the SDK configuration.
Unstable network / high latency The transfer takes longer than the allowed time. Use a stable, high‑bandwidth connection or add retry logic.
Wrong or missing storage name The service spends time trying to resolve a non‑existent storage, then times out. Omit the storage_name parameter (default storage) or verify the name with StorageApi.GetStorageNames().
Server‑side throttling Many concurrent uploads can cause temporary throttling. Add a retry‑with‑back‑off loop.

Step‑by‑step solution (C#)

The example below uses Aspose.Cells Cloud SDK (the same pattern works with the Aspose.Storage SDK). It shows how to:

  1. Increase the HTTP timeout.
  2. Upload the file (single request).
  3. Retry on 504.
  4. Validate / omit the storage name.
using System;
using System.Collections.Generic;
using System.IO;
using Aspose.Cells.Cloud.SDK.Api;
using Aspose.Cells.Cloud.SDK.Client;
using Aspose.Cells.Cloud.SDK.Model;

class Program
{
    static void Main()
    {
        // -------------------------------------------------
        // 1️⃣ Configure the SDK client
        // -------------------------------------------------
        var config = new Configuration
        {
            // Your Aspose Cloud credentials
            AppSid = "YOUR_APP_SID",
            AppKey = "YOUR_APP_KEY",

            // 2️⃣ Extend the timeout – 5 minutes (300 000 ms) is usually enough
            Timeout = 5 * 60 * 1000
        };

        var cellsApi = new CellsApi(config);

        // -------------------------------------------------
        // 2️⃣ Prepare the file to upload
        // -------------------------------------------------
        string localPath   = @"C:\Temp\LargeWorkbook.xlsx";
        string remotePath  = "uploads/LargeWorkbook.xlsx";   // folder in storage
        string storageName = null; // null → default storage (or set a verified name)

        // Read the file into a byte array – required by UploadFileRequest
        byte[] fileBytes = File.ReadAllBytes(localPath);
        var files = new Dictionary<string, byte[]> { { remotePath, fileBytes } };

        // -------------------------------------------------
        // 3️⃣ Upload with a simple retry loop
        // -------------------------------------------------
        const int maxAttempts = 3;
        for (int attempt = 1; attempt <= maxAttempts; attempt++)
        {
            try
            {
                // UploadFile returns an UploadResponse object
                var response = cellsApi.UploadFile(
                    files,
                    remotePath,   // the name (including folder) under which the file will be stored
                    storageName   // can be null
                );

                Console.WriteLine($"Upload succeeded – {response?.Uploaded?.Count} file(s) uploaded.");
                break; // success – exit the loop
            }
            catch (ApiException ex) when (ex.ErrorCode == 504 && attempt < maxAttempts)
            {
                // 504 – gateway timeout → wait a moment and retry
                Console.WriteLine($"Attempt {attempt} timed‑out (504). Retrying in 5 s...");
                System.Threading.Thread.Sleep(5000);
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Upload failed: {ex.Message}");
                throw; // re‑throw or handle as you prefer
            }
        }
    }
}

What the code does

Section Reason
config.Timeout = 5 * 60 * 1000; Extends the HTTP client timeout to 5 minutes (adjust if needed).
storageName = null; Uses the default storage. If you have a custom storage, first call new StorageApi(config).GetStorageNames() to confirm its name.
cellsApi.UploadFile(files, remotePath, storageName) The overload that accepts a Dictionary<string, byte[]> – exactly what UploadFileRequest expects.
Retry loop (for … catch ApiException where ErrorCode == 504) Gives the service a second chance when a transient timeout occurs.

When the file is very large (≥ 100 MB)

The single‑request upload may still be inefficient. In that case:

  1. Use the Aspose.Storage SDK – it provides a multipart upload that automatically splits the payload into 5 MB chunks.
  2. The call looks the same (UploadFile) but the SDK handles chunking internally, so you do not need to write the chunking logic yourself.
var storageApi = new StorageApi(config);
var response = storageApi.UploadFile(files, remotePath, storageName);

If you prefer to keep the file as a single request, make sure the timeout you set is long enough (e.g., 10 minutes for a 200 MB file on a slow connection).


TL;DR

  1. Increase the SDK timeout (config.Timeout = …).
  2. Verify or omit the storage name (use null for the default).
  3. Add a retry‑with‑back‑off loop for occasional 504 responses.
  4. For files larger than ~100 MB, switch to the Aspose.Storage multipart upload (same UploadFile method, SDK does the chunking).

Applying the snippet above should eliminate the 504 Gateway Timeout you are seeing with UploadFileRequest. If the issue persists, let us know the exact file size and the storage name you are using so we can investigate further.

the file I am trying to upload is less than an MB. I am using cellsapi in python.

@abhijittaneja Hello! We’ve successfully tested large-file uploads on our side, and everything is running smoothly. The issue you experienced was most likely caused by a temporary network glitch; our platform team has already investigated and applied a fix. Please try uploading again—if you hit any snags, let us know immediately and we’ll jump in to help right away.

@abhijittaneja, By the way, which version of the Aspose.Cells Cloud SDK for Python are you currently using? We publish the source code on GitHub along with a set of sample scripts for reference. If these don’t cover your needs, just let us know the exact features you’re after and we’ll be happy to help.