djplaner / word-to-canvas-module

A userscript that will create a Canvas Module (including all module items) from a Word document (using special styles)

Home Page:https://djplaner.github.io/word-to-canvas-module/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Canvas API apparently doesn't like big images

djplaner opened this issue · comments

Word docx appears to bork at big images (e.g. first learning module from 1499EDN).

They just disappear -- when converted to HTML this is working, but when added to Canvas, it disappears

Cause is due to Canvas RCE deleteing base64 content

  • is there an error being generated and which can be handled?
  • is there a limit on the API
  • is there a workaround for the limit
  • ??? if not, what's the solution - warning, create image??

Solution

  • Use Javascript to upload file
  • Figure out python to upload a file

Converting base64 images into files saved on Canvas files area

Keep Mammoth base64 images as is in WordConverter. Creating the module would need to

  • detect any base64 images
  • Convert to images and save to Canvas files
  • UPdate the html to point to the URLs of the image files that were saved

The image URL is the full file url with "/preview" on the end

Uploading a file via Canvas API

ufcopen/canvasapi

This works fine it's process is

  • start - open the file into python file handle
  • request_upload_token
    • makes POST request to URL
    • "name" and "size" are the parameters
  • upload
    • passed the response from request_upload_token
    • checks response for "upload_url" and "upload_params" if not there - there's an error
    • generates a new request using the upload_url and the upload_params

Implement trial run

  • Create HTML page with javascript in it that communicates with Canvas API
  • Get it to upload a text file
  • Get it to upload a base64 image