Skip to content

Help Renaming a Remote File #599

Answered by bennettscience
hassr asked this question in Q&A
Discussion options

You must be logged in to vote

This looks like a gap in the File object in the library. There are a couple ways you can do this:

  1. Use the Canvas module to first get the file and then update:
from canvasapi import Canvas
canvas = Canvas(URL, KEY)

# Getting the file this way allows you to confirm you have the right one
# before moving on with the rename. If it's part of a larger script, you
# can also use the included methods on the File object in the library.
# https://canvasapi.readthedocs.io/en/stable/file-ref.html#canvasapi.file.File

file = canvas.get_file(123456)
updated_file = file._requester.request("PUT", "files/{}".format(file.id), name="New display name")

updated_file.json() # should have updated data

The b…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@hassr
Comment options

@bennettscience
Comment options

Answer selected by hassr
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants