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>
Gonzalo Odiard
10 years ago
802 | 802 | |
803 | 803 | del self.unused_download_tubes |
804 | 804 | |
805 | # Use the suggested file, the mime is not recognized if the extension | |
806 | # is wrong in some cases (epub) | |
807 | temp_dir = os.path.dirname(tempfile) | |
808 | new_name = os.path.join(temp_dir, suggested_name) | |
809 | os.rename(tempfile, new_name) | |
810 | tempfile = new_name | |
811 | ||
805 | 812 | _logger.debug("Saving file %s to datastore...", tempfile) |
813 | mimetype = Gio.content_type_guess(tempfile, None)[0] | |
814 | self._jobject.metadata['mime_type'] = mimetype | |
806 | 815 | self._jobject.file_path = tempfile |
807 | 816 | datastore.write(self._jobject) |
808 | 817 |