When trying to upload a file, we get the following response:
<html>
<head><title>500 Internal Server Error</title></head>
<body>
<center><h1>500 Internal Server Error</h1></center>
<hr><center>nginx</center>
</body>
</html>
Performing a PUT request to https://api.aspose.cloud/v3.0/pdf/storage/file/test.pdf
results in the above error.
Reproduce with the following Python script, setting appropriate values for client_id
, client_secret
, and filename
.
import requests
import json
import urllib
import datetime
import time
# fill in with your credentials
client_id = ""
client_secret = ""
# the filename to upload
filename = "test.pdf"
# get bearer token
start = time.perf_counter()
bearer_url = "https://api.aspose.cloud/connect/token"
bearer_headers = {"Content-Type": "application/x-www-form-urlencoded", "Accept": "application/json"}
bearer_data = {"grant_type": "client_credentials", "client_id": client_id, "client_secret": client_secret}
response = requests.post(bearer_url, headers=bearer_headers, data=bearer_data)
data = json.loads(response.content)
bearer_token = data["access_token"]
end = time.perf_counter()
print(f"Got bearer token: {end-start}s")
# uploading a file
start = time.perf_counter()
upload_url = "https://api.aspose.cloud/v3.0/pdf/storage/file/"
upload_header = {"Authorization": "Bearer " + bearer_token, "Content-Type" : "application/octet-stream"}
response = requests.put(upload_url + filename , data=open(filename, 'rb'), headers=upload_header)
print(response)
print(response.content)
Interestingly, the upload through the “slides” API works just fine (but has a different response than the “pdf” API):
PUT request to https://api.aspose.cloud/v3.0/slides/storage/file/test.pdf
returns a JSON with the filename in uploaded
compared to Uploaded
in the https://api.aspose.cloud/v3.0/pdf/storage/file/
request…