-
Notifications
You must be signed in to change notification settings - Fork 76
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
Add settings.setupFormData #44
Conversation
I like the extra The second I favor changing the If you could revert the second change, then i will merge it and create another PR which fixes the |
- otherwise, they will be additional "paste" of the filename into the textarea
Dropped |
LGTM, thanks! I also merged #47 which fixes 2, please try it out if it works for you |
Works great. Thanks! Btw I added code to detect drag drop of inlineAttachment.prototype.isFileAllowed = function(file) {
if (this.settings.allowedTypes.indexOf(file.type) >= 0) {
return true;
} else if (file.type.match(/^text/)) {
if (file.getAsString) {
// copy paste text, ignore
} else if (window.FileReader) {
var that = this;
var reader = new FileReader();
reader.onload = function() {
var current_value = that.editor.getValue();
if (current_value) {
that.editor.setValue(current_value + "\n\n" + this.result);
} else {
that.editor.setValue(this.result);
}
}
reader.readAsText(file)
}
}
}; |
I think the best place would be var options = {
onFileReceived: function(file) {
if (file.type.match(/^text/) && !file.getAsString) {
var that = this;
var reader = new FileReader();
reader.onload = function() {
var current_value = that.editor.getValue();
if (current_value) {
that.editor.setValue(current_value + "\n\n" + this.result);
} else {
that.editor.setValue(this.result);
}
}
reader.readAsText(file);
return false; // return false so default behavior is overriden
}
}
}; |
oops, thanks for the cleanup! unfortunately this code sits after |
hmm, i guess it would make sense to add an extra hook which is called before any validations, something like |
Or maybe regexp/customizable |
It doesn't feel right to do file handling in a hook that is meant to check if a file is allowed or not. I made a new issue #50 to think of an API to allow this. Or i will add this feature to the plugin. |
agreed |
1. Added
settings.setupFormData
Currently
settings.extraParams
appends more fields to the end, after the file itself (which would be very far down the http post payload). pickier server like S3 direct file upload requires the other fields be in front in order to validate (and reject the upload) - so i need to augment theFormData
at the startBut simply copying values over isn't enough, since some extra params are extracted from the file itself, e.g.
Content-Type
in S3 direct file upload. So the solution is to have parameters augmented via a function instead, and passing thefile
along.Optional: with
settings.setupFormData
, we can deprecatesettings.extraParams
2. Added
data(
inlineattachment)
so we can access theinlineAttachment
instance.Ideally I'd use
settings.onFileUploadResponse
to customize how I'd handle the S3 direct upload response and return false.Unfortunately, we cannot access most things that the default
inlineAttachment.prototype.onFileUploadResponse
has access to e.g.this.settings.urlText
,this.filenameTag
,this.editor
One approach is to obtain the
inlineAttachment
instance and attach a customonFileUploadResponse
function directly on it.