diff options
author | Gonzalo Odiard <godiard@gmail.com> | 2014-03-05 20:52:14 (GMT) |
---|---|---|
committer | Gonzalo Odiard <godiard@gmail.com> | 2014-03-05 20:52:14 (GMT) |
commit | c1b27e23baf0ca60d78c6aa325363dd541140ac8 (patch) | |
tree | 745d5ddbbc8e58ed2eeb3d46786d55d8bde8f28e | |
parent | 392ccca583c46b75abd73ea946d42aac588e4006 (diff) |
Save the mimetype in the metadata when download a shared file
Some mime files, like epub, are not recognized if the extension is not set.
We need use the suggested_name extension to save the file,
and save the mimetype in the metadata.
Signed-off-by: Gonzalo Odiard <godiard@sugarlabs.org>
-rw-r--r-- | readactivity.py | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/readactivity.py b/readactivity.py index 19ab4e1..ce39189 100644 --- a/readactivity.py +++ b/readactivity.py @@ -803,7 +803,16 @@ class ReadActivity(activity.Activity): del self.unused_download_tubes + # Use the suggested file, the mime is not recognized if the extension + # is wrong in some cases (epub) + temp_dir = os.path.dirname(tempfile) + new_name = os.path.join(temp_dir, suggested_name) + os.rename(tempfile, new_name) + tempfile = new_name + _logger.debug("Saving file %s to datastore...", tempfile) + mimetype = Gio.content_type_guess(tempfile, None)[0] + self._jobject.metadata['mime_type'] = mimetype self._jobject.file_path = tempfile datastore.write(self._jobject) |