I’m using the files_api to get a signed url. This works when the signed url does not contain an encoded comma (%2c). I receive a 404 error whenever the file url does contain this encoded comma.
How can I work around this?
Code for reference:
def get_file_content(self, file_id)
def get_file_content(self, file_id):
if file_id:
file_detail = self.client.files.files_api.get_signed_url(file_id=file_id).to_dict()
return requests.get(file_detail["url"]).content
Hey @ncrossen,
Thanks for posting in the Community!
Have you, by chance, run this inquiry through the Docs Assistant in our Files API developer doc? If not, I would strongly recommend starting there to see if we can identify even surface level next steps that assist with the overall troubleshooting.
Additionally, I’d like to tag in some Community experts who may have some insight here. @Anton, @SteveHTM, and @EValdes - do any of you have information on why a file url that contains an encoded comma might cause this error?
Shane, Senior Community Moderator
I have used the Docs Assistant! It told me to use the signed-url as is or rename the files (which we cannot do).
Hey @ncrossen,
Thanks for confirming that!
Let’s give the other Community users some time to reply, and we can go off their recommendation(s)! =D
Shane, Senior Community Moderator
@ncrossen - I have sympathy here, as I have been lead astray by the complexities of the file handling approach inside the system.
It’s not entirely clear what you want to achieve here, but I suspect that you are trying to obtain details of the file from it’s ID (like name etc.). If you have the ID itself (just like any other object) you can use the details API call to return this information directly - no need to generate a signed URL. If the file is not public, you will get a 404 error just as though it doesnt exist at all.
In the case of the non-public file, you access the file properties (not the file itself) through the signed URL API call and any returned URL property should not contain % encoded components. You may not be able to see a valid access URL if the file is protected.
Interestingly, when you examine the values of a file type property, you most often see a preview URL as an underlying link to the displayed name. It’s pretty easy to extract the actual file ID from this preview URL which makes for a more straightforward handling of the file object and it’s details.
Hope this is helpful.
Steve
Thanks Steve. My goal is to upload the content of the PDFs to an external system. The files may or may not be public, depending on the deal being enrolled.
This was the only approach I found to be feasible, but I continue getting 404 errors when the file name includes the commas.
I hope you are aware that files uploaded via forms, as an example, are by default set to private and you won’t be able to access the URL directly. I think perhaps that’s the reason you get a 404 error - not as a function of the URL encoding.
Shouldn’t I be able to retrieve the contents of the signed url though?
That’s where I’m getting the error.
You are right - something isn’t adding up here. I’ve always been able to use these kind of mechanics successfully.