Getting 504 Gateway Timeout for HTML to DOCX

Trying to use HTML to Docx Request. Curl Command taken from Docs (Convert HTML to DOCX – Aspose.HTML Cloud SDK),

curl -X POST -v \
	"https://api.aspose.cloud/v4.0/html/conversion/html-docx" \
    -d "{'InputPath': '/sample1.html', 'OutputFile': 'test.docx'}" \
    -H "Content-Type: application/json" \
    -H "Authorization:Bearer <JWT_token>"

HTML file content is very simple,

<html>
  <head>
    <title>This is the title of the webpage!</title>
  </head>
  <body>
    <p>This is an example paragraph. Anything in the <strong>body</strong> tag will appear on the page, just like this <strong>p</strong> tag and its contents.</p>
  </body>
</html>

Getting 504 Gateway Timeout. Kindly help

@avinashs2401

A 504 Gateway Timeout error typically indicates that the server did not receive a timely response from an upstream server while processing your request. Here are a few steps you can take to troubleshoot and potentially resolve this issue when converting HTML to DOCX using the Aspose API:

  1. Check the HTML File Size: Ensure that the HTML file you are trying to convert is not excessively large. Large files can take longer to process, leading to timeouts. If possible, try with a smaller HTML file to see if the issue persists.

  2. Validate the HTML Content: Make sure that the HTML content is well-formed and does not contain any errors. Invalid HTML can cause processing issues. You can use online validators to check the HTML structure.

  3. Increase Timeout Settings: If you have control over the server settings, consider increasing the timeout duration for requests. This can help if the conversion process is taking longer than expected.

  4. Use a Different Method: If the issue continues, you might want to try using an SDK instead of a direct API call. SDKs often handle requests more efficiently and can provide better error handling.

  5. Check Service Status: Sometimes, the service may be experiencing issues. Check the Aspose service status page or forums to see if there are any ongoing outages or maintenance activities.

  6. Contact Support: If none of the above solutions work, consider reaching out to Aspose support for assistance. Provide them with details about your request and the HTML content you are trying to convert.

By following these steps, you should be able to identify the cause of the timeout and find a suitable solution. If you continue to experience issues, please provide more details about your setup and any error messages you receive.

Sources:
[1]: HTML Converter - Convert HTML with Cloud SDK and REST API

Verified everything. File size is just 269 bytes. Content is very simple and well-formed. Need further support on this.
Tried with ruby SDK as well with this code, getting the same 504 timeout error

# load the gem
require 'aspose_html_cloud'

# Get keys from aspose site.
# There is free quota available.
# For more details, see https://purchase.aspose.cloud/pricing

CONFIG = {
    "basePath":"https://api.aspose.cloud/v4.0",
    "authPath":"https://api.aspose.cloud/connect/token",
    "apiKey":"",
    "appSID":"",
    "debug":true
}

api_instance = AsposeHtml::HtmlApi.new CONFIG

src = "/sample1.html"  # String | Full path to the input file.
dst = "/sample1.docx"  # String | Full path to the result.

begin
  #Convert the document from the local file and save result to the local file.
  result = api_instance.convert_local_to_local(src, dst)
  p result
rescue AsposeHtml::ApiError => e
  puts "Exception when calling api_instance.convert_local_to_local: #{e}"
end

Swagger API schema for HTML is also not loading - Aspose.HTML Cloud - API References

Any update on this please? This is completely blocking our development. Kindly help us out on this with high priority.

Hi @avinashs2401 , thanks for waiting. Api reference is located here: Swagger UI
We are checking the issue with conversion that you described. Will get back to you soon

Hi @avinashs2401 please check what it gives you now. It may start working for you or give you more clear details about the error. Please let us know

Hi @andrey.gubal
Getting error now. This is the request,

curl --location 'https://api.aspose.cloud/v4.0/html/conversion/html-docx/sync' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer <Token>' \
--data '{
    "inputPath": "/sample1.html",
    "outputFile": "test.docx",
    "storageName": "test-storage"
}'

Response:

ERROR: One or more errors occurred. ('storage:///sample1.html' could not be found.) 
  STACK TRACE:
   at    .(Boolean )
   at    .(Int32 , CancellationToken )
   at    .()
   at Aspose.Html.HTMLDocument..ctor(RequestMessage , Configuration , Boolean )
   at Aspose.Html.HTMLDocument..ctor(Url url, Configuration configuration)
   at Aspose.Html.Cloud.V4.Applications.Conversion.Impl.HTMLConversionHandler.Execute(ConversionApplicationData data, CancellationToken token) in C:\src\Aspose.HTML.Cloud.V4\Applications\Conversion\Impl\HTMLConversionHandler.cs:line 36
   at Aspose.Html.Cloud.V4.Applications.Conversion.ConversionApplication.Execute(ConversionApplicationData data, CancellationToken token) in C:\src\Aspose.HTML.Cloud.V4\Applications\Conversion\ConversionApplication.cs:line 56
   at Aspose.Html.Cloud.V4.Applications.Conversion.ConversionApplication.<>c__DisplayClass9_0.<ExecuteAsync>b__0(Task`1 x) in C:\src\Aspose.HTML.Cloud.V4\Applications\Conversion\ConversionApplication.cs:line 76
--- Inner: 'storage:///sample1.html' could not be found. ; Aspose.Html.Dom.DOMException   at    . [T](UInt16 , String , String , Object[] )
   at    .(UInt16 , String , String , Object[] )
   at    .(String , Object[] )
   at    ..()
   at    .   ​  ()
   at    .   ​  ()

My Storage:
Screenshot 2025-01-09 at 4.51.52 PM.png (108.8 KB)

@avinashs2401

We are checking it and will get back to you shortly.

@avinashs2401 Do you send just /sample.html or you use the full URL? If you send just filename it will not work because file is not on our server. You would need to send https://example.com/file.html so that we have access to the file. You may upload it to cloud storage and use url to convert. Alternatively you may use our SDK. If you work with .NET you may install our nuget package that allows you converting your local file because it uses our internal cloud storage for conversion. Here is the list of available SDKs: Available SDKs – Aspose.HTML Cloud

Hi @andrey.gubal,
I have uploaded the sample1.html to cloud only.
Overall I have 2 issues,
Issue #1 - Using cURL API

curl --location 'https://api.aspose.cloud/v4.0/html/conversion/html-docx/sync' \
--header 'Content-Type: application/json' \
--header 'Authorization: ••••••' \
--data '{
    "inputPath": "/sample1.html",
    "outputFile": "test.docx",
    "storageName": "test-storage"
}'

Here, the sample1.html is uploaded to Cloud storage only and hence given the inputPath as “/sample1.html” which I believe is correct (or) let me know if this needs to be given in a different way. Attached the screenshot of my storage below,
Screenshot 2025-01-09 at 4.51.52 PM.png (108.8 KB)

Now, I get a different error response than before,

Status: 404
Response: File with path test.docx was not found

I suppose test.docx is something that will be created by the API only. Not sure why its showing error that test.docx was not found.

Issue #2 - Using Ruby SDK (High Priority)
I’m using below code to convert html to docx with files from my local. I’m using the convert_local_to_local method. After completion, the output docx file looks empty.
However when I used the online converter (Convert HTML To DOCX Online) the output docx was fine.
I have attached the input html and output docx files as a zip file.
test_files.zip (71.1 KB)

# load the gem
require 'aspose_html_cloud'

# Get keys from aspose site.
# There is free quota available.
# For more details, see https://purchase.aspose.cloud/pricing

CONFIG = {
    "basePath":"https://api.aspose.cloud/v4.0",
    "authPath":"https://api.aspose.cloud/connect/token",
    "apiKey":"xx",
    "appSID":"xx",
    "debug":false
}

api_instance = AsposeHtml::HtmlApi.new CONFIG

src = "/Users/abc/Downloads/sample1.html"  # String | Full path to the input file.
dst = "/Users/abc/Downloads/html_to_docx_op.docx"  # String | Full path to the result.

begin
  #Convert the document from the local file and save result to the local file.
  result = api_instance.convert_local_to_local(src, dst)
  p result
rescue AsposeHtml::ApiError => e
  puts "Exception when calling api_instance.convert_local_to_local: #{e}"
end

Output in console:

I, [2025-01-10T14:36:41.780656 #75574]  INFO -- : Temp file written to /var/folders/78/s701vyq508q1xvtf5r7vnvvw0000gp/T/download-, please copy the file to a proper folder with e.g. `FileUtils.cp(tempfile.path, '/new/file/path')` otherwise the temp file will be deleted automatically with GC. It's also recommended to delete the temp file explicitly with `tempfile.delete`
#<AsposeHtml::OperationResult:0x00007fca8a01a570 @code=200, @id="CN-45c9b093-ae35-4272-beb8-3fa4bb55b501", @status="completed", @links={:self=>"/v4.0/html/conversion/CN-45c9b093-ae35-4272-beb8-3fa4bb55b501", :download=>"v4.0/html/file?path=html_to_docx_op.docx"}, @file="/Users/abc/Downloads/html_to_docx_op.docx">

Issue with Ruby SDK is of high priority. Kindly look into this and let us know.

@avinashs2401 Thanks for waiting. Had to check a few things. You mentioned that you upload the file first. Do you mean that you use our File API to upload the file (Swagger UI)? Could you please give us response that you receive after uploading the file?

@andrey.gubal I didn’t use the File API to upload. I actually uploaded it directly in the storage using Aspose Dashboard.
On a side note, the issue with Ruby SDK is of priority for us as described in the earlier response. Could you help get it checked soon?

@avinashs2401 Could you give please the url to the page where you do upload? There are many tools in Aspose that can be not connected, so Cloud API may not see the file.

@andrey.gubal This is where I upload the files - Dashboard.
Screenshot 2025-01-13 at 4.43.13 PM.png (31.0 KB)

Also any update on ruby SDK? We have been getting empty docx only as output

@avinashs2401 just a follow-up that we are working on your questions. I’ll get back to you asap

@andrey.gubal Any update?

@avinashs2401 Yes, let’s please check conversion again. Please check if file is still uploaded in your dashboard. It may be cleaned up after some time. The rest must be the same as you tried:
curl --location ‘https://api.aspose.cloud/v4.0/html/conversion/html-docx/sync
–header ‘Content-Type: application/json’
–header ‘Authorization: bearer ••••••’
–data ‘{
“InputPath”: “/sample1.html”,
“StorageName”:“test-storage” // storage name is important in this case. “test-storage” is correct
}’

@andrey.gubal The API is not throwing error now. But the output docx file is just empty when opened in MS Word.
I have attached the input and output files in the zip file at the end. Same output with Ruby SDK also.
Also when I tried using the Convert HTML To WORD Online, the output is fine.
Files in zip,
Input - sample1.html
Output from Aspose Cloud API - output_aspose_cloud_api.docx
Output from Convert HTML To WORD Online - output_aspose_app_online_converter.docx

test_files.zip (81.6 KB)
Screenshot 2025-01-17 at 5.37.13 PM.jpg (231.5 KB)

@avinashs2401 Ok, we are checking