Use base64 for image export/import
jokerejoker - September 7, 2009 - 10:43
| Project: | Node Export |
| Version: | 6.x-2.x-dev |
| Component: | Code |
| Category: | feature request |
| Priority: | minor |
| Assigned: | James Andres |
| Status: | active |
Description
My idea is to use the base64- encode/decode functions with the file_get_contents and file_put_contents function to export the images.
F.eks:
export
$image = file_get_contents($file->filename);
$base = base64_encode($image);
// Some how attach base-code to the array with the file nameimport
$image = base64_decode($array->filedata);
// Write the image
file_put_contents($image, $array->filename);
#1
#2
#3
I don't know much about the file module - perhaps this will mean more to James, but if you're able to explain your motivation a bit it might help?
#4
With the base64 you are able to store an image as a string, and do not have to have access to the folder /tmp/store which most users don't have. How it's technically done I will refer to my previously example of how to use base64 and fetch the file data and put it back in to a new file.
BTW the $array->filename equals the filename fetch at export to put in the image data and $array->filedata equals the $base variable in the export example.
#5
jokerejoker,
Hmm, I'm interested to see someone interested in this :-).
I originally considered this approach, but grew concerned about the file size of the exports. If using base64 encoded files it is not unrealistic for a node export to be a few MB in size, also base64 encoding creates 30% inflated (more bytes) data on average. To be practical, one should consider at least these aspects:
I welcome any ideas you have on the above points!
James
#6
Is it possible to add the base64 method in - but it only gets used by the export if the module is configured to do so by the user?
The import would auto detect which method the pasted code is using.
#7
I see your point with the file size, though it would be great to see this as an option, because I don't have access to the exported files at my host provider.
I think it would be great to export the files to drupal files folder, and have an option to export the files as base64.
#8
If it comes to it, we can add a feature to serve the entire node code as a downloadable file, and an option for an upload in the import screen.
#9
That would be the best solution to my point of view.
#10
I've added the ability to have a downloadable file, which should allow export of a large number of nodes, or a small number of nodes with embedded file/image data, without the issues of having to copy a large amount of text. I hope this is sufficient to enable this issue to progress?
#11
Please give this patch a test, it adds all the requested functionality. It's a fairly big change for the node_export_file module, since I have made base64 the default export option! I think it's a change for the best though.
Also, sorry for the long delay. I have been very busy with client work, like that's any excuse .. ;-).