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
Code bellow and run the plugin. (Ignore if there's a parenthesis missing or something, I went back to try and reconstruct it).
asyncfunctionuploadImages(html: string){// Find images that Ghost Upload supportsletimageRegex=/!*\[\[(.*?)\]\]/g;letimagePromises=[];// Get full-path to imagesletimageDirectory: string;letadapter=app.vault.adapter;if(adapterinstanceofFileSystemAdapter){imageDirectory=adapter.getBasePath();// Vault directoryif(settings.screenshotsFolder){imageDirectory=`${imageDirectory}${settings.screenshotsFolder}`;}if(frontmatter.imageDirectory){// Extends the image directoryimageDirectory=`${imageDirectory}${frontmatter.imageDirectory}`;}}console.log("Image Directory",imageDirectory);letresult: RegExpExecArray|null;// Declare the 'result' variablewhile((result=imageRegex.exec(html))!==null){letfile=`${imageDirectory}/${result[1]}`;// Upload the image, using the original matched filename as a referenceimagePromises.push(api.images.upload({ref: file,file: file}));}returnPromise.all(imagePromises).then(images=>{images.forEach(image=>html=html.replace(image.ref,image.url));returnhtml;});}
Execute the plugin in obsidian and get the following:
Access to XMLHttpRequest at 'http://localhost:2368/ghost/api/v4/admin/images/upload/' from origin 'app://obsidian.md' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
Maybe this is more of a feature request than a bug - nevertheless something annoying.
The text was updated successfully, but these errors were encountered:
Any way you can provide a link to the actual code my dude?
It's quite clear this is a configuration issue that doesn't have to do with ghost. For starters, you probably shouldn't be pointing obsidian to localhost. You need to set up CORS for this. Poke around the interwebs for setting this up for your specific server you have that is serving Ghost.
Issue Summary
I'm writing a plugin uploading images from obsidian to ghost. When running the code bellow it triggers CORS due to the use of axios. See also https://forum.ghost.org/t/cors-using-admin-api-from-electron-app-obsidian/37743/6
To Reproduce
Access to XMLHttpRequest at 'http://localhost:2368/ghost/api/v4/admin/images/upload/' from origin 'app://obsidian.md' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
Maybe this is more of a feature request than a bug - nevertheless something annoying.
The text was updated successfully, but these errors were encountered: