You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Thanks for this package, still perfectly usable 5 years after the last commit! It would be nice if uploading to WebDAV could be supported.
I have successfully implemented it, but the requests/response from and to WebDAV are quite different than the package currently supports. A proper pull request would need quite a bit of refactoring, and I am also not so sure how to stay backwards comptible.
Since I /only/ need WebDAV support, I have overridden the uploadFile method, maybe someone will find it useful or it can be included in the package core one day.
WebDAV uses a dynamic uploadUrl (uploading a file foo.jpg to https://example.com needs a PUT request to https://example.com/foo.jpg, while the file contents should not be encapsulated in any FormData, rendering uploadFieldName obsolete). The response does not contain any data, only the HTTP status code tells if the upload was successful. The resulting filename is the same as the request url, and cannot be extracted from the response.
This is my adaption of uploadFile, to support WebDAV (and only WebDAV), override it like this:
inlineAttachment.prototype.uploadFile=function(file){varme=this,xhr=newXMLHttpRequest(),settings=this.settings,extension=settings.defaultExtension||settings.defualtExtension;// Attach the file. If coming from clipboard, add a default filename (only works in Chrome for now)// http://stackoverflow.com/questions/6664967/how-to-give-a-blob-uploaded-as-formdata-a-file-nameif(file.name){varfileNameMatches=file.name.match(/\.(.+)$/);if(fileNameMatches){extension=fileNameMatches[1];}}varremoteFilename="image-"+Date.now()+"."+extension;if(typeofsettings.remoteFilename==='function'){remoteFilename=settings.remoteFilename(file);}xhr.open('PUT',settings.uploadUrl+'/'+remoteFilename);xhr.onload=()=>{varfilename,newValue;if(xhr.status===200||xhr.status===201||xhr.status===204){filename=xhr.responseURL;newValue=this.settings.urlText.replace(this.filenameTag,filename);}else{newValue="";}vartext=this.editor.getValue().replace(this.lastValue,newValue);this.editor.setValue(text);returnfalse;};xhr.send(file);returnxhr;};// use it like regularinlineAttachment.editors.codemirror4.attach(this.codeMirror,{progressText: '[[Uploading file...]]',urlText: '[[{filename}]]',uploadUrl: 'http://examplecom:8000/uploads',});
The text was updated successfully, but these errors were encountered:
Thanks for this package, still perfectly usable 5 years after the last commit! It would be nice if uploading to WebDAV could be supported.
I have successfully implemented it, but the requests/response from and to WebDAV are quite different than the package currently supports. A proper pull request would need quite a bit of refactoring, and I am also not so sure how to stay backwards comptible.
Since I /only/ need WebDAV support, I have overridden the
uploadFile
method, maybe someone will find it useful or it can be included in the package core one day.WebDAV uses a dynamic
uploadUrl
(uploading a filefoo.jpg
tohttps://example.com
needs aPUT
request tohttps://example.com/foo.jpg
, while the file contents should not be encapsulated in anyFormData
, renderinguploadFieldName
obsolete). The response does not contain any data, only the HTTP status code tells if the upload was successful. The resulting filename is the same as the request url, and cannot be extracted from the response.This is my adaption of
uploadFile
, to support WebDAV (and only WebDAV), override it like this:The text was updated successfully, but these errors were encountered: