Skip to content
This repository has been archived by the owner on Nov 2, 2023. It is now read-only.

Allow multiple embedded file types. #30

Merged
merged 3 commits into from
Feb 6, 2021
Merged

Conversation

jheddings
Copy link
Contributor

Uses the generalized block type for uploading files.

Resolves #29

@Cobertos
Copy link
Owner

Cobertos commented Feb 6, 2021

Do all the if statements still apply to this use case?

if re.search(r"(?<!file)://", imgRelSrc, re.I):
    return #Don't upload images that are external urls
if imagePathFunc: #Transform by imagePathFunc insteadif provided
    imgSrc = imagePathFunc(imgRelSrc, mdFilePath)
else:
    imgSrc = relativePathForMarkdownUrl(imgRelSrc, mdFilePath)
    if not imgSrc:
        print(f"ERROR: Local image '{imgRelSrc}' not found to upload. Skipping...")
        return
print(f"Uploading file '{imgSrc}'")
newBlock.upload_file(str(imgSrc))

I guess it works for your use case because Day One was putting video and PDF attachments in Markdown image syntax? Otherwise I'd think you'd run into issues with relativePathForMarkdownUrl when trying to load your files.

The more I look at this, the more I don't understand why imagePathFunc didn't just default to relativePathForMarkdownUrl, but maybe with a function partial on mdFilePath,,, A chore for the future I think

I would add a comment in the code that it's expecting an ImageBlock but also supports other blocks, just to clarify why it's the super classes. but otherwise LGTM

@jheddings
Copy link
Contributor Author

Do all the if statements still apply to this use case?

Yes, they are still valid, since it is still possible to reference an external file. That would still be rendered as a standard image block.

I guess it works for your use case because Day One was putting video and PDF attachments in Markdown image syntax? Otherwise I'd think you'd run into issues with relativePathForMarkdownUrl when trying to load your files.

Correct... It uses the image syntax as a generic "embedded" media type.

The more I look at this, the more I don't understand why imagePathFunc didn't just default to relativePathForMarkdownUrl, but maybe with a function partial on mdFilePath,,, A chore for the future I think

In my case, I was changing the block type before calling upload to ensure that Notion used the right block. uploadBlock ended up skipping my blocks since they were of type VideoBlock of PDFBlock.

I would add a comment in the code that it's expecting an ImageBlock but also supports other blocks, just to clarify why it's the super classes. but otherwise LGTM

Good call. Done.

@Cobertos
Copy link
Owner

Cobertos commented Feb 6, 2021 via email

@Cobertos Cobertos merged commit 8c0eef5 into Cobertos:master Feb 6, 2021
@Cobertos
Copy link
Owner

Cobertos commented Feb 6, 2021

Thanks for the PR!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unable to upload different media types.
2 participants