API upload via url inconsistent results

Hi All,

Looking for some insight into this one.
I am trying to get uploads to work via API and I keep getting the error

{"errors"=>["Sorry, you must provide a file to upload."]}

This happens when I try to upload a generated public url from canvas i.e.


If I use another url i.e.


it seems to work.

I can definitely browse to the url via browser and display the pdf file.
What am I doing wrong here?


It looks like that url isn’t browsable and has some permission locking on it. Your browser can access it because you are logged in to aws, but your Discourse instance cannot access it because it has not been authorized.

1 Like

The URL has an expiry set on it, that is probably why you can’t see it now. It is generated on the fly when using the Canvas API

It is difficult to show you but here is another URL that has just been generated. I can access it from incognito browser too.


I guess I am just trying to find out why these kinds of files are not able to be uploaded via Discourse API and others are.

Something is still up with that url. Chrome is just being fancy and loading it right away for you (handling the headers or something).

Once you are able to get it to work with curl -O <url> it should work in Discourse.


When using curl -O <url> It kept giving errors: Warning: Failed to create the file
But I can get curl -0 <url> -o filename.pdf to work.
Can discourse use other curl command lines? Or can I somehow get it to perform the same download as curl -0 <url> -o filename


I’m unable to get curl -0 <url> -o filename.pdf to work. Can you verify that the filename.pdf is the actual pdf document and not just some xml error.

Also -0 just changes it to “Use HTTP 1.0 (H)” where as -O saves it as a file instead of trying to render the pdf in the console.

The Discourse app doesn’t actually use curl to download the file, but it is just a good way to test anonymous downloads of files and when the discourse app uses ruby to download the file it does do something similar to curl.

In order to determine what the issue is here can you provide some more info on how your s3 bucket file permissions are setup? How do you generate all the extra url parameters to allow “anonymous” access to a private file?

Another option might be to use curl or whatever your using to access the discourse api to download the file or use the aws-sdk to download the file as an authenticated user and then upload the actual file to the discourse api instead of just a url.

Also once you get this all working you might want to turn on this setting in Discourse “prevent anons from downloading files”.


Thanks for the tip.
I ended up downloading the file to local storage and then uploading to Discourse.
A bit hacky but works well.


1 Like