cancel
Showing results for 
Search instead for 
Did you mean: 
jerosalazar
Community Member

Problem with verifier when downloading a file. Canvas API

I'm currently trying to download files using the canvas API and I'm having an issue with the file's url. In every explanation that I can find the url follows this structure:

"http://<canvas>/files/<id>/download?download_frd=1&verifier=[verifier]"

 But every time I look up the information of a file in my organization, I never get the verifier with it. The structure I always get looks like this:

"https://<canvas>/files/<id>/download?download_frd=1"

I don't know if there's something that I'm missing or maybe my organization doesn't allow access to files with this type of user validation

 

Thanks in advance

0 Kudos
1 Reply
JamesSekcienski
Community Participant

I don't see a verifier when I look at the API results either, at least not with the couple I tested.

If you are working with JavaScript, you could use the URL to create an anchor tag that opens in a new tab and then simulate a click on it.  After clicking it you could remove the anchor tag.

function downloadCanvasFile(url) {
  let downloadAnchor = document.createElement("a");
  downloadAnchor.href = url;
  downloadAnchor.target = "_blank";
  document.body.appendChild(downloadAnchor);
  downloadAnchor.click();
  document.body.removeChild(downloadAnchor);
}

downloadCanvasFile("https://<canvas>/files/<id>/download?download_frd=1");

 

If you want to rename the file before downloading, you can use the download attribute, but you will also have to strip away the download part of the URL after the id.

function downloadCanvasFile(url, filename) {
  let downloadAnchor = document.createElement("a");
  downloadAnchor.href = url;
  downloadAnchor.download = filename;
  downloadAnchor.target = "_blank";

  document.body.appendChild(downloadAnchor);
  downloadAnchor.click();
  document.body.removeChild(downloadAnchor);
}

downloadCanvasFile("https://<canvas>/files/<id>/download?download_frd=1", "desiredFilename.fileExtension");

 

I only tested in Chrome, so I'm not sure if this is fully supported in other browsers.