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

Image import fails when inserting HTML or image from clipboard #857

Closed
echo511 opened this issue Feb 19, 2018 · 23 comments
Closed

Image import fails when inserting HTML or image from clipboard #857

echo511 opened this issue Feb 19, 2018 · 23 comments

Comments

@echo511
Copy link

echo511 commented Feb 19, 2018

Expected behaviour

Should store images into media/.

Actual behaviour

In the bar at the bottom it says the image was downloaded but nothing is actually imported - no file in media folder, no snipped in note inserted.

Output from the debug section in the settings dialog

Current Date: po úno 19 19:26:38 2018
Version: 18.02.3
Build date: Feb 19 2018
Build number: 417
Platform: linux
Operating System: Arch Linux
Build architecture: x86_64
Current architecture: x86_64
Release: AUR
Qt Version (build): 5.10.1
Qt Version (runtime): 5.10.1
Portable mode: no
Settings path / key: /home/.../.config/PBE/QOwnNotes.conf
Application database path: /home/.../.local/share/PBE/QOwnNotes/QOwnNotes.sqlite
Application arguments: QOwnNotes
Qt Debug: 0
Locale (system): cs_CZ
Locale (interface): empty
Icon theme: Numix-Square
Notes in current note folder: 16
Enabled scripts: 1

Relevant log output (you have to enable enable the log widget)

[úno 19 19:29:12] [debug]: insertHtml  - 'imageUrl':  QUrl("https://avatars1.githubusercontent.com/u/658504?s=88&v=4")
[úno 19 19:29:12] [status]: Downloading https://avatars1.githubusercontent.com/u/658504?s=88&v=4
[úno 19 19:29:17] [status]: Downloading images finished
@pbek
Copy link
Owner

pbek commented Feb 19, 2018

When I copy your image from this webpage with a bit of other text on Linux I get

AssigneesNo one—assign yourself

LabelsNone yetProjectsNone yetMilestoneNo milestoneNotifications UnsubscribeYou’re receiving notifications because you’re subscribed to this repository.

1 participant[![media-AM2270](file://media/1074265970.png)
](https://github.com/echo511)[ **Lock conversation**](https://github.com/pbek/QOwnNotes/issues/857#lock-confirmation)[![media-WT2270](file://media/1328689228.png)
](https://github.com/echo511)   [](https://github.com/contact/report-content?content_url=https%3A%2F%2Fgithub.com%2Fpbek%2FQOwnNotes%2Fissues%2F857&report=echo511+%28user%29)
### **[echo511](https://github.com/echo511) **commented [18 minutes ago](https://github.com/pbek/QOwnNotes/issues/857#issue-298367819)

Works perfectly fine for me.

@pbek
Copy link
Owner

pbek commented Feb 19, 2018

Does it work on other webpages, like on www.qownnotes.org?

@echo511
Copy link
Author

echo511 commented Feb 19, 2018

I tried to copy some content from your website. In log I have

[úno 19 21:09:53] [debug]: insertHtml  - 'imageUrl':  QUrl("http://www.qownnotes.org/var/bekerle/storage/images/_aliases/medium/qownnotes/frontpage-slider/qownnotes-external-modification-notification-linux/846-7-eng-GB/QOwnNotes-External-Modification-Notification-Linux.png")
[úno 19 21:09:53] [status]: Stahování http://www.qownnotes.org/var/bekerle/storage/images/_aliases/medium/qownnotes/frontpage-slider/qownnotes-external-modification-notification-linux/846-7-eng-GB/QOwnNotes-External-Modification-Notification-Linux.png
[úno 19 21:09:53] [status]: Downloading images finished

In actual note this was pasted:

## Screenshot
[](http://www.qownnotes.org/var/bekerle/storage/images/_aliases/lightbox_fullscreen/qownnotes/frontpage-slider/qownnotes-main-screen-linux/374-25-eng-GB/QOwnNotes-Main-Screen-Linux.png)
## Features
[](http://www.qownnotes.org/var/bekerle/storage/images/_aliases/lightbox_fullscreen/qownnotes/frontpage-slider/qownnotes-external-modification-notification-linux/846-7-eng-GB/QOwnNotes-External-Modification-Notification-Linux.png)- the **notes folder** can be **freely chosen** (multiple note folders can be used)- **sub-string searching** of notes is possible and search results are highlighted in the notes- application can be operated with **customizable** **keyboard shortcuts**- **scripting support** and an online [**script repository**](https://github.com/qownnotes/scripts) where you can install scripts inside the application- **external changes** of note files are **watched** (notes or note list are reloaded)- older **versions** of your notes can be **restored** from your **ownCloud / Nextcloud** server

Images are not present.

@echo511
Copy link
Author

echo511 commented Feb 19, 2018

@pbek Maybe a lead. I've tried to import Evernote .enex and after import has been completed no images or attachments were present - the options have been checked.

@pbek
Copy link
Owner

pbek commented Feb 19, 2018

Maybe your system is unable to detect images (missing libraries?). Or no write permission to the media folder... Something seems amiss...

@echo511
Copy link
Author

echo511 commented Feb 19, 2018

Permissions are not the problem. Inserting images from filesystem through drag&drop or context menu is working.

@echo511
Copy link
Author

echo511 commented Feb 19, 2018

I am also running full Gnome environment. It is pretty robust. Or is it missing some special library? Thanks for suggestions.

@pbek
Copy link
Owner

pbek commented Feb 19, 2018

The Qt libraries should be enough... Inserting the images is done by

/**
* Returns the markdown of the inserted media file into a note
*/
QString Note::getInsertMediaMarkdown(QFile *file, bool addNewLine,
bool returnUrlOnly) {
if (file->exists() && (file->size() > 0)) {
QDir mediaDir(NoteFolder::currentMediaPath());
// created the media folder if it doesn't exist
if (!mediaDir.exists()) {
mediaDir.mkpath(mediaDir.path());
}
QFileInfo fileInfo(file->fileName());
QString suffix = fileInfo.suffix();
QMimeDatabase db;
QMimeType type = db.mimeTypeForFile(file->fileName());
// try to detect the mime type of the file and use a proper file suffix
if (type.isValid()) {
QStringList suffixes = type.suffixes();
if (suffixes.count() > 0) {
suffix = suffixes[0];
}
}
// find a random name for the new file
QString newFileName =
QString::number(qrand()) + "." + suffix;
QString newFilePath = mediaDir.path() + QDir::separator() + newFileName;
// copy the file to the media folder
file->copy(newFilePath);
QFile newFile(newFilePath);
scaleDownImageFileIfNeeded(newFile);
QString mediaUrlString = "file://media/" + newFileName;
// check if we only want to return the media url string
if (returnUrlOnly) {
return mediaUrlString;
}
// return the image link
// we add a "\n" in the end so that hoedown recognizes multiple images
return "![" + fileInfo.baseName() + "](" + mediaUrlString + ")" +
(addNewLine ? "\n" : "");
}
return "";
}

I wonder whats happening on your machine...
What is your enabled script doing?

@echo511
Copy link
Author

echo511 commented Feb 19, 2018

@pbek You were correct. I have installed gpaste and now everything works as expected. Thank you for your lightning support. Perfect application. Will throw some coin to support your superb work. Closing the issue.

@echo511 echo511 closed this as completed Feb 19, 2018
@pbek
Copy link
Owner

pbek commented Feb 19, 2018

Thank you for your kind words!
What libraries where installed by gpaste?

@pbek
Copy link
Owner

pbek commented Feb 19, 2018

It seems like some more libraries are needed in https://github.com/pbek/QOwnNotes/blob/develop/build-systems/aur/PKGBUILD

@echo511
Copy link
Author

echo511 commented Feb 19, 2018

Libs "installed":

gtk3
wgetpaste (optional) - Upload clipboard contents
appstream-glib (make)
git (make)
gnome-control-center (make)
gnome-shell (make)
gobject-introspection (make)
intltool (make)
vala (make)

But I have to reopen because it is only partial solution for use case when the image alone is in clipboard. When copying HTML, images are still not present. :(

Link is copied, missing image:

[](https://media.novinky.cz/763/667631-original1-5k217.jpg)

@echo511 echo511 reopened this Feb 19, 2018
@echo511
Copy link
Author

echo511 commented Feb 19, 2018

And to clarify the partial fix. The gpaste daemon has to be running for it to work.

@pbek
Copy link
Owner

pbek commented Feb 19, 2018

I have the same problem on my Manjaro Laptop (KDE Neon worked fine)...
It seems no QTemporaryFile will be created in Note::downloadUrlToMedia.

@echo511
Copy link
Author

echo511 commented Feb 19, 2018

I have installed the whole qt5 but the issue persists.

@pbek
Copy link
Owner

pbek commented Feb 20, 2018

I'll have to investigate more... But I still have no idea why temporary files behave differently on Arch, could be a Qt upstream problem...

@pbek
Copy link
Owner

pbek commented Feb 20, 2018

Interesting, file->exists() is false on Arch Linux for QTemporaryFile in Note::getInsertMediaMarkdown.

@pbek pbek added this to the 18.02.4 milestone Feb 20, 2018
@pbek
Copy link
Owner

pbek commented Feb 20, 2018

18.02.4

  • fixed a problem with downloading media files on Arch Linux

@echo511
Copy link
Author

echo511 commented Feb 20, 2018

@pbek Should be solved via #858 I have tested it and it works.

@pbek
Copy link
Owner

pbek commented Feb 20, 2018

thank you, I've not commited my fix yet, but I already fixed it ;)

@pbek
Copy link
Owner

pbek commented Feb 20, 2018

There now is a new release, could you please test it and report if it works for you?

@echo511
Copy link
Author

echo511 commented Feb 20, 2018

@pbek Tested successfully. As a pleasant side-effect it also fixed importing images from Evernote's .enex file. Thanks again for insanely fast support.

@echo511 echo511 closed this as completed Feb 20, 2018
@pbek
Copy link
Owner

pbek commented Feb 20, 2018

Great, thank you for reporting and testing!

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

No branches or pull requests

2 participants