Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds support for base64 Files #95

Open
wants to merge 25 commits into
base: master
Choose a base branch
from

Conversation

kazachoc
Copy link

@kazachoc kazachoc commented Feb 6, 2021

This PR adds support for handling base64 encoded file fields.

if(this.isBase64(file)){
const newfile = this.dataURItoBlob(file);
// file = `${URL.createObjectURL(blob)}`;
const fname = `${this.uuidv4()}.png`;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like that .png is hardcoded after the filename. (We might want to add support for non-image files later.)


saveFile(name) {
const snakeName = camelToSnake(name);

if (this.__fileChanges[name]) {
const file = this.__fileChanges[name];

// debugger;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will just remove this useless line.

@action
setInput(name, value) {
invariant(
this.__attributes.includes(name) ||
this.__activeCurrentRelations.includes(name),
`Field \`${name}\` does not exist on the model.`
);
this.isBase64File = false;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need this? It looks like this value is never read.
Also, I don't believe this variable makes sense: what should it be when the model has both a regular file field and a base64 file field? The current implementation seems to base this decision on just the type of the last file field.

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

Successfully merging this pull request may close these issues.

2 participants